As per Hindu legend, Indra, the king of celestial deities, presented his white elephant to Muruga, the son of Shiva, during his marriage at Thiruparakundram. The divine couple travelled on the elephant. When Vishnu wanted to view the couple, they appeared at Thirumagaral.
As per another legend, a ruler of the region wanted the fruit from a jack fruit tree in the place wanted it to be offered to Chidambaram Nataraja Temple every day and subsequently to him.
He ordered the local public to carry out the activity every day. Once it was a turn of a boy in the village to carry the fruit. He felt that the king has made an undue order and wanted it to be eliminated. He burnt the tree thinking that the villagers would be relieved off the duty.
The king enquired the boy, who fearlessly narrated the truth. The king was angry with him and started chasing him to punish. He found a golden iguana cross his way to an anthill.
The king dug the anthill only to see blood woozing out. A divine voice told him that it was Shiva who appeared that and the king had to build a temple for his propitiation. Since Shiva appeared as magaral, an iguana, the place came to be known as Magaral and Shiva is called as Magaraleeswarar
.

Child Sambandar praying to Shiva
The original complex is believed to have been built by Cholas, while the Rajagopuram and masonry structure was built during the Vijayanagar Dynasty Nayakkar Kings during the 15th century. There are several inscriptions from the period of Kulothunga Chola I (reigned 1070–1120), Sundara Pandiyan and Vicayakanta Kopaletevar, indicating generous gifts to the temple.
In modern times, the temple is maintained and administered by the Hindu Religious and Charitable Endowments Department of the Government of Tamil Nadu.
It is one of the shrines of the 275 Paadal Petra Sthalams - Shiva Sthalams glorified in the early medieval Tevaram poems by Tamil Saivite Nayanmars Thirugnana Sambanthar. As the temple is revered in Tevaram, it is classified as Paadal Petra Sthalam, one of the 276 temples that find mention in the Saiva canon. As per Periya Puranam, the hagiography depicting the life of the 63 Nayanmars, Sambandar visited the place before moving on Kuranganilmuttam and Kanchipuram.