Māṇḍavya (Mandavya) was a Puranic hermit, wise and honest, calm and composed. One day when he was engaged in performing austere tapasyā (tapasya) by stretching his arms up and observing the vow of silence under a tree in his hermitage, a band of thieves entered his hermitage with a load of stolen goods. They were being pursued by the royal guards, who also arrived at the hermitage after a few moments. Meanwhile, the thieves concealed the stolen goods and themselves in various corners of the hermitage. When the guards, entering the hermitage, did not see the criminals, they asked the only available person about them: the sage Māṇḍavya. As Māṇḍavya was observing the vow of silence, he returned no reply to the guards’ questions. The irritated guards took it upon themselves to look for the thieves and the stolen materials and they succeeded. But they grew suspicious of the sage who had kept mum throughout the ordeal. Therefore they arrested the sage as well, taking him for an abettor of the miscreants, and presented him along with the thieves in front of the king.
The outcome of the trial was that the king sentenced the sage as well along with the thieves to death by pinning on śūla (shula; spiked iron pole stuck into the ground. Convicts were executed by pinning them on the spiked pole so as the spike penetrated the anus and came out through the flesh of the neck and the convicts died an extremely painful death). Neither the king, nor the guards noticed that it was a wise hermit they were sentencing to death – a person who could not be prosecuted from any quarter. The event yielded a miraculous result: although the thieves died on the spiked poles, Sage Māṇḍavya, even speared on the spiked head of the pole, remained alive by virtue of the occult power he had earned through tapasyā. Bereft of food and sleep, nailed on the spike, the sage remained alive for long to catch the notice of the attending guards, who conveyed of this miraculous occurrence to the king. Immediately the king left the palace to visit the sage and begged for the latter’s forgiveness for the unjustifiable wrong he had committed unknowingly. Māṇḍavya was pleased with the king who ordered to release him from the spiked pole. However, the entire pole could not be removed from the sage’s body. Although the long shaft of the pole gave way, the spiked head would not come out of his bottom. Therefore the shaft had to be cut off and Māṇḍavya had to wander across the world and perform tapasyā with the spiked head of the pole stuck inside his anus. The spiked head of a śūla is called aṇī (ani) in Sanskrit. Because of the spike sticking in his body, Māṇḍavya got the epithet of Aṇīmāṇḍavya (Animandavya).
One day, while carrying the spike in his rectum, a groaning Aṇīmāṇḍavya met Dharma, the deity of dharma (righteousness, principle and justice). He asked Dharma whether he had ever committed a wrong unknowingly for which he was being subjected to this insufferable pain. Dharma replied, “Once you penetrated the bottom of a grasshopper with the blade of a reed. You are being punished for that act of cruelty.” The sage asked, “How old was I when I committed this act of cruelty?” “You were a child then,” Dharma replied. The sage said, “A wrong committed by a child between his infancy and twelve year of age is not considered a crime anywhere – not even by the gods.” Then he cursed Dharma, “You have punished me heavily even though my wrong was of a light nature. I curse you for this wrong you committed to me. You shall be born in the mortal world as a man of lowly caste (Śūdra; shudra). And let me announce that hereafter the wrongs committed by one till he is fourteen years of age would not be accountable as crimes” – ācaturdaśakād varṣān na bhaviṣyati pātakam.
In Mahābhārata (Mahabharata) we find that due to this curse of Aṇīmāṇḍavya, Dharma incarnated as Vidura to a Śūdra woman – dharmo vidurarūpeṇa śūdrayonāvajāyata.
Sage Māṇḍavya himself recounted this narrative in Anuśāsanaparva (Anushasanaparva) of Mahābhārata. Along with other sages he also had come to pay a visit to Bhīṣma (Bhishma), who was lying on the bed of arrows. After a recital of Śivasahasranāmastotra (Shivasahasranamastotra), a verse praising the one thousand names of God Śiva (Shiva), everyone gathered there eulogised the glory of Śiva. It is then that we find Māṇḍavya retelling this story of his life and concluding that he ultimately got relieved of the spike in his body by pleasing Śiva with his tapasyā.