In ancient times, a great sin was committed by Indra, the king of the gods, which led to chaos and imbalance in society. Due to this sin, Lord Mahadev (Shiva) went into meditation, and Mother Parvati became lonely.
Mother Parvati's maternal instinct had awakened and the desire for a child started growing within her. To fulfill her loneliness and desire for motherhood, Mother Parvati decided to create a child herself. She mixed the sandalwood paste from her body with the soil and gave it the shape of a child and breathed life into it. Thus, a small child was born, whom Mother Parvati named "Vinayak".
After a few years, when Vinayak was about ten years old, Lord Shiva returned with his ganas. At that time Mother Parvati was taking a bath and she said to Vinayak, "Make sure that no one comes inside." Vinayak, following his mother's orders, guarded the gate. Since Vinayak had never seen Shiva, when Lord Shiva reached there, Vinayak stopped him.
Shiva's Ganas and Devtas tried to stop Vinayak, but he remained adamant. Seeing this, Lord Shiva became angry, and cut off Vinayak's head with his trident.
When Mother Parvati came out after bathing and saw her beloved son lying without a head, she became extremely angry. Her anger was so terrible that the creation started moving towards destruction. Shiva tried to calm her down, but Mother Parvati did not listen.
Mahadev had also beheaded his son Vinayak due to a curse. Lord Shiva had given death penalty to Sun God due to his arrogance and not performing his duty. Saddened by this, Sage Kashyap, who was the father of Sun God, cursed Lord Shiva in grief that in future you will also have to behead your own son and suffer the pain of son separation.
Seeing the possibility of destruction of the creation due to this fierce anger of Mother Parvati, Lord Brahma and Vishnu requested Mahadev to calm the mother. Mahadev immediately sent his followers Indra and Nandi to the north direction and said that the first creature found and whoever gives his head voluntarily, his head will be placed on Vinayak.
Indra and Nandi found an elephant in the north direction, whose name was Gajasur. Gajasur was a wise and great elephant, who was once blessed by Mahadev that he would always live on Kailash. Gajasur gladly handed over his head to Indra.
Lord Shiva attached Gajasur's head to Vinayak's body and Vinayak was thus reborn. He was renamed Ganesha, which means "Lord of the Ganas".