According to the Linga-Purâna, Ganesh is created by Shiva to triumph over Asuras and other enemies of the gods; indeed, the Devas begged Almighty Shiva to come to their aid because they were being harassed by the demons.
Shiva consented to it and, with his wit, made a child burst forth with an elephant's head. Seeing this beautiful child, Pârvatî put it on his knee and decreed that no enterprise, human or divine, would be successful without first having a prayer. Shiva made him the leader of the celestial hordes, the Gana, calling him Ganapati, which means Chief of Ganas.
A more detailed variant repeats the episode of Parvati and his son guarding his house. Shiva, exhausted at not being able to pass, sent the army of his Ganas to the assault. But Ganesh rout them; Shiva then brings Brahma peacefully, in the form of a Brahman, trying to bring the boy back to his senses. In vain.
Then Shiva asks Kartikeya and Indra to intervene and raise their armies; Ganesh resists victoriously thanks to the support of Kali and Durga, called to the rescue by Pârvatî, furious that one attacks his dear son ...