There are many stories about Lord Ganesha’s birth, this one is the most popular. According to this, one day Goddess Parvati went to take a bath, she asked Nandi to guard the door and not let anyone inside.
But being Lord Shiva’s faithful, when Shiva came, he didn’t stop him from entering. Seeing that she didn’t have anyone as faithful to her as Nandi was to Shiva, she collected the turmeric paste she used to clean her body with, and moulded the paste to a handsome boy, Ganesha.
Now when Lord Shiva came, he was duly challenged by Ganesha, which culminated into a battle and the boy losing his life.
Read the full story here: Birth of Lord Ganesha and Ganesha Chaturthi Festival