As per popular legend, near the temple of Tirukkadaiyur, there lived a sage named Mrikandu and his wife Marudmati. They were both devotees of Shiva and worshiped him day and night for many years, asking that he grace them with a child. After many years of penance, Shiva appeared to Mrikandu and Marudmati.
He told them that he heard their prayers and would give them a choice: they could either have a gifted son who would live to only sixteen, or a son of low intelligence who would live a long life. Mrikandu and Marudmati chose the former, and were blessed with Markandeya, an exemplary son, destined to die at the age of sixteen.
As Markandeya grew, so did his devotion to Shiva. As advised by his father, Markandeya worshipped the Shiva Lingam at Tirukkadaiyur, even bringing water from the Ganges to the temple via an underground passage. On the day he was destined to die, Yama, the deity of death, appeared with his noose to tie around the soul of Markandeya and take it with him.
Markandeya sought refuge in the Uyyakondan temple and embraced the Siva Lingam and got relief in Thirukkadaiyur. Shiva appeared and warned Yama not to touch Markandeya, as he was under his protection.
Yama refused to listen and threw the noose anyway, binding Markandeya and the Lingam together. Angered by Yama's extraordinary arrogance, Shiva kicked him and held him under his foot, making Yama inactive.
C

Shiva saving Markendeya from Yama
The temple is built in Sembian age of Cholas around 950 CE. There are many inscriptions in the temple. An inscription from the period of Rajaraja I indicates donation of a crown to the temple by Sembiyan Mahadevi during his 10th regnal year.
The temple has inscriptions dating from Kulothunga Chola I (1070–1118 CE), that speaks of a separate community known as Rathakarar, a sect of expert carpenter skilled in the art of designing and making temple car
The Uyyakondan Channel was built as a tributary by Rajaraja Chola to irrigate the lands near Tiruchirapalli.
The temple was occupied by French and English forces during the siege of Trichonopoly (old Tiruchirapalli) in 1753-54.[3] After the war battle of Sugar-loaf rock, English Major Lawrence marched against the fortified temple and carried it by assault In modern times, the temple is maintained and administered by the Hindu Religious and Charitable Endowments Department of the Government of Tamil Nadu.