According to the stories narrated in the Shiva Purana, it was in the Treta yuga that the demon Ravana, king of Lanka, felt that his capital would not be perfect and free from enemies unless Mahadeva stays there forever. He paid continuous meditation to Mahadeva. Ultimately Shiva got pleased and permitted him to carry his lingam with him to Lanka. Mahadeva advised him not to place or transfer this lingam to anyone. There should not be a break in his journey to Lanka. If he deposits the lingam anywhere on the earth, in the course of his journey, it would remain fixed at that place forever. Ravana was happy as he was taking his return journey to Lanka.
The other gods objected to this plan; if Shiva went to Lanka with Ravana, then Ravana would become invincible and his evil and anti-vedic deeds would threaten the world. Therefore the gods tricked Ravana. Ravana was offered water by Parvati, who then directed all the waters of three rivers (Ganges, Yamuna and Saraswati) into Ravana's stomach.
On his way back from Mount Kailash, Ravana felt an urgent need to urinate and as he could not do so with the holy linga in his hand, he started looking for someone who could hold it for him. Ganesha then appeared as a Brahmin in front of him. Ravana asked Ganesha to hold the linga and went to release himself, but he could not stop urinating because of the trick played on him. Ganesha, pretending to be vexed by Ravena's delay, set the linga down on earth. The moment linga was kept down, Ravana stopped urinating.
Ravana needed to wash his hands after urination to make himself pious. Finding no water source around he hit the ground with his fist and a big crater was made which got filled with water. When Ravana now tried to move the linga, he could not. Out of anger he press the linga down with his thumb. But after restoring himself, he started to offer his prayers for the linga.