Sri Naradiya Purana mentions how Janamejaya was cured of leprosy by taking refuge under the feet of Guruvayuruppan. The Pandavas handed over the kingdom to their grandson Parikshit, and left for the forest to spend their last days. Parikshit died of the curse of a saint, who cursed that Parikshit will die of snake bite by Takshaka, the king of serpents. After the death of Parikshit he was succeeded by his son Janamejaya. Janamejaya conducted a sacrifice to destroy all the snakes of the world including Takshaka, who was the cause of his father's death . Hundreds of thousands of snakes fell into the sacrificial fire and were killed, but the sacrifice was stopped by a Brahmin called Astika, before Takshaka was killed.
Since Janamejaya was responsible for the death of millions of snakes, he was afflicted with leprosy. He lost all hope of a cure. One day Sage Atreya (son of Atri) came before Janamejaya and told him to take refuge under the feet of Krishna at Guruvayoor. Atreya told him that in the temple at Guruvayur the effulgence of Sri Hari is at its best and Vishnu showers his blessings on all devotees. He immediately rushed there and spent the next ten months worshipping the God at Guruvayur. At the end of ten months, he returned home hale and hearty and took the astrologer to task for making a false prediction. The astrologer told him that he would find the mark of a snakebite on his left leg. He had escaped death only because he was at that time in a temple where Anantha (the emperor of serpents) was present and Anantha was the brother to the God at Guruvayur where he had finished worshipping.
The king being convinced of the astrologer's verdict decided to build a full-fledged temple at Guruvayur. In course of time, this temple came to be downgraded and reduced to poverty during the days when Kerala was ruled by the Perumals. The Perumal rulers were mostly Shaivites and did not extend their patronage to Vaishnavite shrines. The Shiva temple at Mammiyur received their patronage and with the shift of royal patronage, the worshippers also swung more to the Shiva temple. The Guruvayur temple was thus reduced to utmost poverty, without even means to light the temple lamp. However, one day, a holy man went to the Mammiyur temple for food and hospitality for the night. Though the temple was affluent, the temple authorities pretended they had nothing and scornfully directed him to the neighbouring Guruvayur temple knowing fully well that the temple was in destitute conditions. When the holy man entered the precincts of that temple, he was courteously received by a brahmin boy and sumptuously fed. The holy man was very much pleased and he pronounced a blessing. "I came here from Mammiyur temple, because they said there is nothing there," he said."They told me also that there is plenty here. Well hereafter it will be exactly like that!" It is said from that day, Mammiyur Siva temple began to decline, and the fortunes of Guruvayur Vishnu temple progressed from strength to strength. But now, Mammiyur is also progressing by the number of devotees.
According to legends, the deity worshipped here is more than 5000 years old. In the 14th century, “Kokasandesam” (a Tamil literary work), references to a place called Kuruvayur are made. As early as the 16th century (fifty years after Narayaniyam was composed) many references to Kuruvayur are seen. In ancient Dravidian languages, “kuruvai” means “sea”, hence the village on the Malabar Coast may be called Kuruvayur. The earliest temple records date back to the 17th century. The earliest mention of the many important Vishnu temples of Kerala is found in the songs of Alwars, Tamil saints, whose timeline is not exactly fixed. Mamankam was a very famous local event at Tirunavaya, on the bank of Bharatappuzha. The battles between the Kozhikode under Samoothiris and Valluvanad popularised Guruvayur Temple. Due to the prolonged battles, people across the riverbank started preferring Guruvayur. Even the Samoothiri of Kozhikode become a devotee and thus his subjects followed him. The central shrine that is seen today is said to have been rebuilt in 1638 AD. “Viswabali” was performed later to propitiate all the spirits, good and bad. By the end of the 16th century, Guruvayur had become the most popular pilgrimage center in Kerala.
In the Colonial age
Mamankam was a very famous event at Thirunavaya, on the bank of Bharathappuzha. The war between the Zamorins and the Raja of Valluvanad of Thirunavaya in a way popularised Guruvayur temple. Due to the prolonged war, people across the river bank started preferring Guruvayur. Even the Zamorin become a devotee and thus his subjects followed him completely. The central shrine which we see today is said to have been rebuilt in 1638 AD. Vishwabali was performed later to propitiate all the spirits, good and bad. By the end of 16th century, Guruvayur had become most popular pilgrimage center in Kerala.
In 1716 AD, the Dutch raided Guruvayur. They looted treasures, gold of the flagstaff, and set fire to the Western Gopuram. It was later rebuilt in 1747 AD. In 1755AD, the Dutch in a war with the Zamorin destroyed Trikkunavay temple and the Brahmins fled from there. Later the Zamorin become the trustee of both Guruvayur and Trikkunavay, and also their Melkoyma (Sovereign protector).
In 1766 AD, Hyder Ali of Mysore captured Kozhikkode (Calicut) and then Guruvayur. He fined 10,000 fanams to spare the temple. This fine was paid but due to insecurity pilgrims receded, the supply of rice was stopped and the tenants stopped annual dues. On the request of the Malabar Governor, Srinivasa Rao, Hyder Ali granted a Devadaya (free gift) and the temple was saved from extinction. Again in 1789 AD Tippu Sultan invaded Zamorin’s province. Apprehending the destruction, the idol was hidden underground and the Utsava vigraha was taken to Ambalapuzha by Mallisseri Namboodiri and Kakkad othikkan. Tippu destroyed the smaller shrines and set fire to the Temple, but it was saved due to timely rain. Tippu lost to the Zamorin and the English in 1792 AD. The idol is hidden underground and the Utsava vigraha was re-installed on September 17, 1792. But the daily poojas and routines were seriously affected.
Ullanad Panikkars rescued and looked after the temple from 1825 to 1900. Like Chempakasseri Nambudiri and Desavarma Nambudiri, Panikkars offered everything from service to property. Thus with their help daily puja and annual festivals were once again restored. From 1859 to 1892, the Chuttambalam, the Vilakkumatam, the Koottambalam and Sasta shrine were renovated and roofed with copper sheeting. In 1900, Konti Menon, as a manager fixed the hours of worship and led the drive to keep the temple premises clean. He set up the big bell and reconstructed Pattayappura (granary). In 1928, Kozhikode once again became the administrator of Guruvayur.
On November 30, 1970, a massive fire broke out in the temple. It began from the western Chuttambalam (circumambulatory temple) and raged all around for five hours, but the Sreekovil (sanctum sanctorum), the main deity, sub-shrines of Ganesha, Ayyappa, Bhagavati, and Flagstaff remained unaffected. This shocking incidence of fire took place on 29 November during the season of Ekadasi Lighting. The day was celebrated on a grand scale and all the lamps in the Vilakkumatham (a frame on the outside a Sanctum Sanctorum of a temple covered with oil lamps in rows from top to bottom) with wher san were lighted. After last Siveli procession, the temple and the gates of Gopuram were closed for the day. Around 1.00am, somebody in the immediate neighborhood near the western Chuttambalam saw a blaze from within the Temple. Roused by the news, a lot of local people, rushed to the Temple and joined in fighting the fire with water and sand. Later, the fire force units of Ponnani, Trichur, and Fertilisers and Chemicals Travancore arrived and started fighting the fire which seems to have started from the western Vilakkumatam. It was brought under control by 5.30 am. Seeing the uncontrollable fire, the authorities had already removed the valuables from the Sreekovil. The Ganapathy deity, Sastha deity and the main deity of God Guruvayurappan were shifted to the Koothambalam and then to a safer place, the residence of the Tantri. The fire gutted the whole of chuttambalam, the entire Vilakkumatam on the west, south and north sides. Even though it was only 3 yards from the Chuttambalam, the fierce fire did not touch the Sreekovil.