According to legend, the Atmalinga was perforce placed at Gokarna, in the temple precincts where it is now deified. It was Ravana, the demon King of Lanka, known from the epic, Ravana had carried it there from Mount Kailash in the Himalayas.
This is one of the holiest site for shiva and finds its mention in several Puranas, Ramayana and the Mahabharata.
The temple's first construction was by the king Mayurasharma of the Kadamba dynasty (reign 345 CE – 365 CE).
Again, legend holds that Mayurasharma wished to learn of the Vedic rites and the Ashwamedha Yagna (ritual of horse sacrifice).
He travelled to Kanchipuram, a major religious learning centre, but there, he was insulted by a horseman guard. He was angered and swore to defeat the ruling Pallava dynasty.
Following his defeat of the Pallavas, the king asked some priests to perform a daily yajna to maintain his suzerainty over the region. Mayurasharma's son, King Kangavarma brought Brahmin families from different lineages to maintain administration at the temple.
The classical Sanskrit writer, Kalidasa mentions the "Lord of Gokarna" in his 4th century work, Raghuvamsha. The Gokarna temple is recorded as one of the Paadal Petra Sthalams in the 7th century Tevaram by Appar and Sambandar wrote canon of devotional poetry.
The temple is a large complex of shrines and much of it belongs to the later Vijayanagara period (1336–1646 CE). A Vijayanagara emperor once visited the temple and weighed himself in gold.
During the 17th century reign of Queen Chennammaji and her son, Soma Sekharanayaka of Keladi, Visvesvaraya of Halasunadu-Kundapura built the Chandrasala and Nandi pavilions. In 1665, the warrior king, Shivaji (1630 CE - 1680 CE) worshipped at the Mahabaleshwar temple after disbanding his army in Gokarna.
In 1676, Fryer, an English traveller, visited Gokarna during the Maha Shivaratri festival and wrote in detail about it at the temple.
The temple is located on the shores of Arabian Sea on the west coast of India, near the city of Karwar. It is set in a lush, green environment in the holy town of Gokarna (also spelt "Gokarn") in Uttara Kannada (or North Kannada district).
Gokarna lies between the Gangavalli and Aganashini rivers.

The hoary legend of the temple as narrated, links Ravana of the Ramayana, the demon king of Lanka, not only to the Shiva Linga deified in the Mahabaleshwar Temple but also to Gokarna's Bhadra Kali temple. The legend also provides etymology of the place name, "Gokarna".[7]
Ravana's mother, a staunch devotee of Lord Shiva, was worshipping a Shiva Linga to bring prosperity to her son. Indra, the Lord of Heaven, who was jealous of this worship, stole the Shiva Linga and threw it away into the Sea. The distraught mother of Ravana went on a hunger strike as her devotional worship of Shiva was disrupted.

Ravana then promised his mother that he would go to Mount Kailash, the abode of Lord Shiva, and bring the main Atmalinga itself for her worship. Ravana then performed severe penance at Mount Kailash to please Lord Shiva and also sang, in his melodious voice, praises of Shiva (Shiva Tandava Stotram).
He even chopped his own head, and made a harp with threads drawn from his skin and intestine. Lord Shiva was pleased and he appeared before him and offered a wish. Ravana requests the Atma-Linga as his boon. Lord Shiva agrees to give him the boon with a condition that it should never be placed on the ground.
If the Atma-Linga was ever placed on the ground, it would remain rooted at that spot. Having obtained his boon, Ravana started back on his journey to Lanka
As Ravana was nearing Gokarna, Lord Vishnu blotted out the sun to give the appearance of dusk. Ravana now had to perform his evening rituals but was worried because with the Atma-Linga in his hands, he would not be able to do it. At this time, Lord Ganesha in the disguise of a Brahmin boy accosted him.
Ravana requested him to hold the Atma-Linga until he performed his rituals, and asked him not to place it on the ground. Ganesh struck a deal with him saying that he would call Ravana thrice, and if Ravana did not return within that time, he would place the Atma-Linga on the ground.
Ganesha called out thrice rapidly but Ravana couldn't come within the specified time. Even before Ravana could return, Lord Ganesha placed the Atmalinga on the ground, tricked Ravana and vanished from the scene with his cows. Ravana then chased the only cow, which was going underground.
However, he managed to get hold of the cow's ear, as the rest of cow's body had disappeared below ground. It is this ear now seen in a petrified form, which has given the name "Gokarna" to the place. The word "Gokarna" means "cow's ear" where in Sanskrit gow means "cow" and karna means "ear".
Then, Ravana tried hard to lift the Shiv Linga but failed as it was firmly fixed. Ravana had even fainted; thereafter he gave the name "Mahabaleshwar" (meaning all-powerful) to the Atmalinga

Thus, according to the legend narrated, the place now boasts of three divine entities namely: Gokarna, the cow's ear; the Atmalinga or Shiva Linga that is deified in the Mahabaleshwar Temple; and the Goddess Bhadrakali, which are all now divine places of worship integral to Gokarna.

Left: Dravidian style Gopura of Mahabaleshwar temple at Gokarna. Right: Pradakshinapath (circumambulatory path) of Mahabaleshwar temple at Gokarna.
The temple is built of granite in the Dravidian architectural style. The Atmalinga is enshrined in the temple on a square Saligrama Peetha (pedestal). The pedestal has a small hole at its centre from where devotees can see the top of the Atmalinga.
Foreigners, including practicing Hindus of non-Indian (Western) origin are not allowed to enter the sanctum-sanctorum and see the Shivalinga.