When Basmasuran was killed by Siva & Vishnu (Vishnu in the form of Mohini), Duraasadan, Basmasuran's son was angry and upset. He did tapas & got boons from Siva that he should never die and that all the devas should be under his control, etc.
As usual Siva gave him the varam & there was total chaos for some time. All the Devas ran into hiding & even Brahma & Vishnu ran out of their Brahma Logam & Vaikundam. All of them rushed to Kasi which was ruled by Viswanathar. On hearing of this Duraasadan came to Kasi. All the Gods and Devas rushed away to Kedaram, because the time was not yet right to kill Duraasadan.
Soon, on the prayers of the Devas, an avataram of Lord Ganesha came out of Uma Devi's face. (with five faces, 10 hands, Jada magudam with moon). Uma Devi named him Vakradhundar and gave him her Simha Vahanam (lion).
There ensued a heavy fight between Vakradhundar & Duraasadan. Finally Ganesha took a huge form (Viswa roopam) & placed his feet on Duraasandan's head. Since Ganesha is the form of Gnanam, all evil thoughts & the effects of his evil deeds rushed out of Duraasadan. Lord Ganesha gave him the job of destroying all evil in Kasi. He remains under Vakradhundar's feet doing his duty.