Ganesha’s first avatara is of Vakratunda , an embodiment of the Absolute Impersonal aspect of Godhood. A demon named Matsara was born out of the Pramaada of Indra. This demon performed severe penance and invoked the grace of Lord Shiva and obtained the boon of fearlessness from Him. Having obtained the boon he went about conquering all the three worlds," The defeated gods went to Kailasa and prayed to Lord Shiva for protection. Lord Dattatreya advised the gods to invoke the grace of Lord Vakratunda and imparted to them the secret of the monosyllable mantra Gam. All the gods including Shiva did penance accordingly and at last Lord Vakratunda appeared and assured them that he would subdue the demon. The demon was so terrified at the sight of Vakratunda that he surrendered to Him and sought refuge at His feet. The Lord forgave him, and restored the lost glory and kingdoms to the gods, and to the various kings on earth.
https://www.google.com/search?q=Vakratunda
https://www.google.com/search?q=Vakratunda