The soonest history of the city is in Treta Yuga, Ravana (Demon/Asura King of Lanka) comes to Kailasa and performed thorough repentance to get the "Atma Linga" from Lord Shiva, as Ravana's mom communicated a sharp want to venerate the atmalinga of Lord Shiva. After a long retribution, Shiva gave the Atma linga to Ravana as a shelter and educates Ravana to convey it home by walk, that he ought to never put it on the earth in any event, for a brief timeframe bombing which the linga would get interminably installed at where he broke his orders. 

Master Maha Vishnu discovered that Ravana will turn out to be almighty by venerating the 'Atma Linga' and threat to the world and Ravana's conviction that no one could crush him, when he obtained the very intensity of Shiva. Maha vishnu concocted an arrangement to introduce the linga some place and as he felt that Lord Ganapati was separated from everyone else fit for doing it, he alongside all the divine beings satisfied Ganapati to execute the arrangement. Ruler Ganapati acknowledges and comes to Gokarna as a Brahmin kid. 

As Ravana was approaching Gokarna, Maha Vishnu who had known well that Ravana was dependable in playing out his periodical customs (Sandyavandhana), shrouds sun with his Sudarshana Chakra (Wheel). Believing that the time had come to play out the night customs, Ravana finds a Brahmin kid and requested that he grasp the Atmalinga till he returned subsequent to completing the rituals. Ganapati consented to hold the linga on one condition that he would do as such till he would have the option to endure the heaviness of linga and that from that point he would call Ravana multiple times and whenever neglected to come to him by then he would put the linga on the earth. 

Ganapati calls Ravana multiple times when he was playing out his rituals and spots the linga on the earth and he disappeared. The Atmalinga without a moment's delay got solidly settled in the earth. Ravana discovered that he had been deceived by the Gods. The discouraged evil presence lord Ravana was profoundly upset and attempted to pull up the linga, yet the linga didn't move a bit. It brought about his tossing the covers of the Linga to Dhareshwara, Gunavanteshwara, Murudeshwara and Shejjeshwar sanctuaries. 

Ravana couldn't lift the linga from the beginning and called the Shiva linga as Mahabala, one with extraordinary quality, and from that point onward, the linga renowned as Mahabaleshwara. Shiva took in all these from Vayu Deva, the lord of wind, and made advances on Earth with Goddess Parvathi devi and his train of Gods, he visited these five spots and adored the linga which had now taken five structures. He recognized that these five spots would be his "Pancha Kshetras" (Five Holy Places). 

Gokarna was important for the Sodhe and Vijayanagar realms. At the point when the Konkan locale — including Goa — was involved by the Portuguese, it turned out to be essential for their standard.