History of the temple
King Mahabali was noted for his boldness & charitableness. He was loved by his people. This made the emperor very proud and he disrespected the gods and Devas. Maharshi Narada met Lord Shiva at Mount Kailash and asked him to punish King Mahabali. Lord Shiva said that once in his temple when a lamp was about to extinguish, King Mahabali in the form of a rat made the lamp burn continuously. So, the Lord rewarded the King the rule of 56 kingdoms. Lord Shiva said to Narada that it would be unjustified to destroy Mahabali in his present birth. Later, Maharshi went to Lord Vishnu and asked Him to punish Mahabali for his egoistic character.
Lord Vishnu went to Mahabali as a Vamana and wanted three feet land. Vamana measured the world in two footsteps and demanded for third and Mahabali offered his head instead. He was pushed into padala lokam. A distressed Dharma Devata, mother of Mahabali who lost her son met Lord Shiva and asked for justice. Lord Shiva punished Lord Vishnu with cancer on the foot that squashed Mahabali's head. When Vishnu needed relief, Lord Shiva told him to bathe in 18 holy theerthas. Lord Vishnu came to Thiruvetriyur for a holy bath and his cancer disappeared.