The legend

Mahabali was the grandson of Prahlada (son of Hiranyakashyapa who was slain by Vishnu in his Narasimha Avatara). Prahlad, despite being an Asura, had great faith in Vishnu. Mahabali learned the act of love and devotion to Lord Vishnu as a child, from Prahlada.
Mahabali conquers the three worlds

Kashyapa had two wives, Diti and Aditi, who were the parents of the demons and the gods (Asuras and Devas) respectively. Kashyapa, who had gone to the Himalayas to do penance, on his return found Aditi weeping. By divine insight, Kashyapa instantly recognised the cause of her grief. He tried to console her saying that nothing happens in the world without divine will and people should go on doing their duties. He asked her to pray to Vishnu and taught her Payovrata, a ritual that has to be observed from the 12th day of the bright half of Karthika (Sukla-paksha Dvadasi). Since Aditi carried out the Vrata with a pious heart, Vishnu appeared before her and informed her that he would help Indra.

Alternatively, the Devas were very annoyed as Mahabali became the ruler of all the three worlds having defeated the Devas. Devas, the celestial beings, were annoyed and jealous. The gods approached Vishnu and asked for his help. Vishnu said to the Devas that Mahabali is doing good things to his subjects and is eligible to become sura (devas). You devas should not be jealous about that. Being jealous would make you asuras. Vishnu decided to test Mahabali.

In the meantime, Mahabali was performing the sacrificial rite of the Viswajith Yagam or Aswamedha Yagam on the banks of the Narmada River. He also declared that he would give anything that anyone sought from him during this Yagam.

Vamana visits Mahabali

Taking advantage of the Yagam and Mahabali's declaration, Vamana (Vishnu disguised as a Brahmin) came to the Yaga-shala. As he approached them, the sages assembled there perceived the extraordinary effulgence form of the young lad. Mahabali went forth to receive the Brahmin boy with all traditional honours and gave him an eminent seat befitting the status of a holy person. With the usual courtesy given to the people who come to ask for help, Mahabali told him that it was his good fortune that Vamana had chosen to honour him with his presence. Whatever Vamana desired, Mahabali was ready to fulfill. Vamana smiled and said: "You need not give me anything great. It is enough if you give me that extend of land covered by three footsteps of mine".

On hearing him, Mahabali's preceptor, Shukracharya (a Daitya priest), who had visions of the future, told Mahabali that the one who had come to take alms from him was not an ordinary Brahmin but Lord Vishnu Himself having assumed this form. He advised Mahabali not to promise the lad anything. But Mahabali was a king who would never go back on his word, considering it sinful to do so. Shukracharya insisted that he should not fulfill the demand of Vamana as he had come to deprive him of all his possessions.

Mahabali, determined to honour his promise, begged the pardon of his Guru for disregarding his advice. Earlier, while Mahabali was embarking on the war with Indra, he had prostrated at the feet of his preceptor, Shukracharya, and on his advice had he started the Vishwajith Yagam from which he secured some very powerful weapons. It was only because of Shukracharya's help that he was able to conquer Indra. Mahabali's refusal angered Shukracharya. He cursed Mahabali, saying: 'As you have not heeded your Guru's words, you will be reduced to ashes'. Mahabali was firm and replied: 'I am prepared to face any consequence but will not go back on my word'.

Mahabali's reign ends

Saying so, he asked Vamana to measure the desired three feet of land. All attempts of Shukracharya to dissuade Mahabali proved futile. Mahabali considered everyone who came to him for help as god himself and never refused them anything. Mahabali told his Guru: "Prana (life) and Maana (honour) are like the two eyes of a person. Even if life goes, honour should be protected. Knowing that the person that has come now is the Lord Himself, I should be the most fortunate one as the Lord, who gives everything to mankind, is seeking something from me." Mahabali gladly said that even if Vishnu himself were to come to his sacrifice and ask for anything, he would deliver it.

Vamana grew in size until he towered above the heavens. With one footstep, he measured all of the earth. With the second, he claimed all of heaven. There was still one foot of territory that Mahabali owed him. Mahabali requested Vamana to place the final step on his head as the third step of land, for he had no other left. Vamana did so and in doing so, pushed him down to Patala, the underworld (the kingdom beneath the earth). The site where he placed his foot is said to be the village of Thrikkakara (meaning place of the holy foot), and is the centre of the renowned Onam festival celebrated in relation to the legend of King Mahabali.
Vishnu's blessings

For the devotion of this daitya, Mahabali, Lord Vishnu (Vamana) granted him rule over the underworld. It was also granted that he would hold the position of Indra for one Manvantara, thus fulfilling his devotee's desire (the office of Indra being a rotating position, changing every Manvantara).

As a last gift, Mahabali was granted permission to visit his subjects once a year. Thus, Keralites celebrate the Onam festival to commemorate the memory of the Great King Mahabali who would keep his promise to visit. Mahabali fulfilled his name as the great martyr for the sake of Truth ("Satya"). The name "Mahabali" itself means Great Sacrifice.

During Onam, the feast and festive mood of the people, dressed in their best, is considered reminiscent of the prosperous and truthful life of the subjects during Mahabali's flawless reign. People wear new clothes (Vastra) during Onam. The 'Vastra' also stands for heart. Thus the significance of wearing new clothes is about making the heart new by removing all bad thoughts and feelings. People forgetting their sectarian outlooks, join together to welcome the auspicious 'Thiruvonam' day.

Alternate Legend

By traditional beliefs; Parasurama, an incarnation of Vishnu is credited to have founded Kerala. An alternate legend defines Onam as the day on which Parasurama recovered Kerala from the sea-bed by throwing his battle-axe. The axe traveled from Gokarnam in the North to Kanyakumari in the South. This legend is mentioned by Hermann Gundert in his Malayalam Dictionary.