Srimad Bhagavatam 8th Canto http://vedabase.net/sb/8/4/en
SB 8.4.6: Because Gajendra, King of the elephants, had been touched directly by the hands of the Supreme Personality of Godhead, he was immediately freed of all material ignorance and bondage. Thus he received the salvation of sārūpya-mukti, in which he achieved the same bodily features as the Lord, being dressed in yellow garments and possessing four hands.
SB 8.4.7: This Gajendra had formerly been a Vaiṣṇava and the king of the country known as Pāṇḍya, which is in the province of Draviḍa [South India]. In his previous life, he was known as Indradyumna Mahārāja.
SB 8.4.8: Indradyumna Mahārāja retired from family life and went to the Malaya Hills, where he had a small cottage for his āśrama. He wore matted locks on his head and always engaged in austerities. Once, while observing a vow of silence, he was fully engaged in the worship of the Lord and absorbed in the ecstasy of love of Godhead.
SB 8.4.9: While Indradyumna Mahārāja was engaged in ecstatic meditation, worshiping the Supreme Personality of Godhead, the great sage Agastya Muni arrived there, surrounded by his disciples. When the Muni saw that Mahārāja Indradyumna, who was sitting in a secluded place, remained silent and did not follow the etiquette of offering him a reception, he was very angry.
SB 8.4.10: Agastya Muni then spoke this curse against the King: This King Indradyumna is not at all gentle. Being low and uneducated, he has insulted a brāhmaṇa. May he therefore enter the region of darkness and receive the dull, dumb body of an elephant.
SB 8.4.11-12: Śukadeva Gosvāmī continued: My dear King, after Agastya Muni had thus cursed King Indradyumna, the Muni left that place along with his disciples. Since the King was a devotee, he accepted Agastya Muni's curse as welcome because it was the desire of the Supreme Personality of Godhead. Therefore, although in his next life he got the body of an elephant, because of devotional service he remembered how to worship and offer prayers to the Lord.
SB 8.4.13: Upon delivering the King of the elephants from the clutches of the crocodile, and from material existence, which resembles a crocodile, the Lord awarded him the status of sārūpya-mukti. In the presence of the Gandharvas, the Siddhas and the other demigods, who were praising the Lord for His wonderful transcendental activities, the Lord, sitting on the back of His carrier, Garuḍa, returned to His all-wonderful abode and took Gajendra with Him.
Copied from Shiv Chanda FB