In the Bhagavata Purana Indradyumna was a saintly king who was engaged in deep meditation. One day he was visited by the sage Agastya. Indradyumna did not notice the arrival of Agastya, who took the king’s neglect for an insult. Agastya was enraged and cursed Indradyumna to become a mighty tusker, the elephant Gajendra. The grief-stricken Indradyumna asked Agastya to liberate him from the curse. Agastya said that he would be redeemed from the curse by Vishnu’s touch.
Indradyumna, now as Gajendra, lived as an elephant for many years. One day he went to drink water from a lake at Mount Trikuta. In that lake lived a former gandharva named Huhu, who also had been cursed. He had disturbed the sage Devala’s devotions when the sage saw Huhu frolicking with celestial maidens (apsaras) in the lake near his hermitage. Devala’s curse turned Huhu into a crocodile.
When Indradyumna as Gajendra the elephant stepped into the lake to drink, Huhu the crocodile caught hold of his hind leg and tried to drag him under. They fought for a thousand years. Gajendra in great pain prayed to Vishnu, offering lotus flowers with his trunk. The prayer made by Gajendra on this occasion became a famous hymn in praise of Vishnu called the Gajendra Stuti. Vishnu came and killed Huhu and redeemed Indradyumna from the curse. Indradyumna immediately attained Vaikuntha, the abode of Vishnu.