The Shivling at Mahakaleshwar Temple in Ujjain, Madhya Pradesh, India, is the third among the twelve Jyotirlingas. There is an interesting story, which explains about the origin of the Shivling worshipped in the Mahakaleshwar Temple. The story is mentioned in the Shiva Purana.
Legend has it that a powerful demon live on Ratnamal Mountain in Ujjain. The demon caused havoc in the city of Avanti – former name of Ujjain. There was a pious man in the city who was an ardent devotee of Shiva.
The demon killed the pious man by setting him afire.
Killing of his devotee angered Lord Shiva. Shiva appeared at Avanti, opened his third eye, and burnt the demon and his entire army to ashes.
A Shivling appeared on the spot where Lord Shiva opened his third eye and killed the demon.