When they were defeated by the demons, the devas fled to Meru mountain. They went to Lord Brahma and Lord Vishnu for help. God advised them to go into hiding and work in Mahakal van, where Lord Shiva would protect them. Under the protection of Lord Shiva, the Devas eventually defeated the rakshasas again. Ujjain thus came to be called as Avanti puri (Avan means the protector).