Goddess Parvati wanted to bathe. She summoned the bull-god Nandi and ordered him to guard the entrance to the bath chamber. Sometime later, Lord Shiva arrived at the door wishing to speak to Parvati. Nandi told Shiva that Parvati had commanded him not to let anyone in while she was bathing. Shiva replied that he was Parvati's husband; therefore, he had the right to see her whenever he pleased. Nandi reluctantly let him in. Later, Parvati reproached Nandi for letting Shiva in while she was bathing. Nandi replied that he was, after all, Lord Shiv's mount (vehicle) and dared not disobey his master.
Before her next bath, Parvati made a statue of a boy out of turmeric paste she had applied to her body. She breathed life into the statue, which turned into a young boy. She named the boy—her son—Ganesha, which means "lord of the ganas." (The ganas are the attendants of Lord Shiva and live on Mount Kailash.) She ordered him to guard the door while she bathed and also armed him with a divine staff and iron club to beat up anyone who tried to enter without her permission.
Lord Shiva arrived at Parvati's door only to find it guarded by a boy wielding a staff and a club. Shiva expressed his desire to meet Parvati, but Ganesha explained that Parvati was bathing and did not wish to meet anyone. Shiva did not wish to use force against the lad and resumed his seat at the summit of Mount Kailash. Later, he commanded Nandi and his other attendants to remove Ganesha by force from the entrance to Parvati's bath chamber. A battle ensued, but Ganesha easily defeated his opponents.
Indra, the king of the gods, volunteered to persuade Ganesha to stop blocking the door. When words failed, Indra and the other gods resorted to violence but were no match for Parvati's son. Lord Vishnu then confronted Goddess Parvati's son, Ganesha. The two were evenly matched and fought each other for a long time. Vishnu split Ganesha's iron club into two with his Sudarshana Chakra. Ganesha then struck Vishnu with his staff. Lord Shiva seized this opportunity when Ganesh was distracted and flung his Trident at Ganesh's neck. The boy's head was severed and destroyed by the power of Shiva's Trishula. Ganesh's headless body fell to the ground.
Hearing the commotion outside and Ganesha's cry, Parvati quickly emerged from the bath chamber only to find the headless Ganesha lying on the ground. She was distraught and told Shiva that her son had only followed her instructions. A livid Parvati summoned her alternative forms—including the fearsome Durga and Kali—and together they threatened to cause a cataclysm that would destroy the universe and its inhabitants. Lord Brahma begged Parvati to forgive them. Parvati said that she would spare them only if her son were resuscitated.
Shiva thought for a while and then ordered his attendants, "Travel north and bring me the head of the first creature you encounter." Shiva's attendants set out on the journey, and the first creature they encountered was an elephant. It was actually Gajasura (meaning, Elephant-Demon), who was an ardent devotee of Lord Shiv. They cut off his head and brought it to Shiva. This was done in accordance with Gajasura's wishes, and thus he attained salvation.
Shiva attached the elephant's head to Ganesha's headless body and infused Ganesha with new life. Parvati was overjoyed when her son, now with an elephant's head, stood up and bowed to her. Shiva then decreed that people would invoke Lord Ganesha before the beginning of any auspicious task.