On one occasion, the Blessed One was living at Mithila in the Makhadeva Mango Grove. Then in a certain place the Blessed One smiled. It occurred to the venerable Ananda: "What is the reason, what is the cause, for the Blessed One's smile? Tathagatas do not smile for no reason." So he arranged his upper robe on one shoulder, and extending his hands in reverential salutation towards the Blessed One, he asked him: "Venerable sir, what is the reason, what is the cause, for the Blessed One's smile? Tathagatas do not smile for no reason."
Buddha replied: "Once, Ananda, in this same Mithila there was a king named Makhadeva. He was a righteous king who ruled by the Dhamma, a great king who was established in the Dhamma. He conducted himself by the Dhamma among brahmins and householders, among town-dwellers and country folk, and he observed the Uposatha days on the fourteenth, fifteenth, and eighth of the fortnight. Now at the end of many years, many hundred years, many thousand years, King Makhadeva addressed his barber thus: 'Good barber, when you see any grey hairs growing on my head, then tell me.' 'Yes, sire,' he replied. And after many years, many hundred years, many thousand years, the barber saw grey hairs growing on King Makhadeva's head. When he saw them, he said to the king: 'The divine messengers have appeared, sire; grey hairs are to be seen growing on your majesty's head.' King: "Then, good barber, pull out those grey hairs carefully with tweezers and put them in my palm.' Yes, sire, he replied, and he pulled out those grey hairs carefully with tweezers and put them in the king's palm. "
"Then King Makhadeva gave the best township to his barber, and calling the prince, his eldest son, he said: 'Dear prince, the divine messengers have appeared; grey hairs are seen growing on my head. I have enjoyed human sensual pleasures; now it is time to seek divine sensual pleasures. Come, dear prince, take over the kingship. I shall shave off my hair and beard, put on the yellow robe, and go forth from the home life into homelessness. And now, dear prince, when you too see grey hairs growing on your head, then after giving the best township to your barber, and after carefully instructing the prince, your eldest son, in kingship, shave off your hair and beard, put on the yellow robe, and go forth from the home life into homelessness. Continue this good practice instituted by me and do not be the last man. Dear prince, when there are two men living, he under whom there occurs a breach of this good practice - he is the last man among them. Therefore, dear prince, I say to you: Continue this good practice instituted by me and do not be the last man.'"
"Then, after giving the best township to his barber and after carefully instructing the prince, his eldest son, in kingship, in the Makhadeva Mango Grove he shaved off his hair and beard, put on the yellow robe, and went forth from the home life into homelessness. "He abided pervading one quarter with a mind imbued with loving-kindness, likewise the second, likewise the third, likewise the fourth; and everywhere, and to all as to himself, he abided pervading the all-encompassing world with a mind imbued with loving-kindness, abundant, exalted, immeasurable, without hostility and without ill will. "
"He abided pervading one quarter with a mind imbued with compassion...with a mind imbued with appreciative joy...with a mind imbued with equanimity, likewise the second, likewise' the third, likewise the fourth; and everywhere, and to all as to himself, he abided pervading the all-encompassing world with a mind imbued with equanimity, abundant, exalted, immeasurable, without hostility and without ill will."
"For eighty-four thousand years King Makhadeva played childish games; for eighty-four thousand years he acted as vice-regent; for eighty-four thousand years he governed the kingdom; for eighty-four thousand years he led the holy life in this Makhadeva Mango Grove after shaving off his hair and beard, putting on the yellow robe, and going forth from the home life into homelessness. By developing the four divine abodes, on the dissolution of the body, after death, he passed on to the Brahma-world. "
"Now at the end of many years, many hundred years, many thousand years, King Makhadeva's son addressed his barber thus:...(as above)......By developing the four divine abodes, on the dissolution of the body, after death, he passed on to the Brahma-world. The descendants of King Makhadeva's son to the number of eighty-four thousand kings in succession, after shaving off their hair and beard and putting on the yellow robe and went forth from the home life into homelessness in this Makhadeva Mango Grove. They abided pervading one quarter with a mind imbued with loving-kindness...with compassion...with appreciative joy.. .with equanimity.. .without ill will. For eighty-four thousand years they played childish games; for eighty-four thousand years they acted as viceregents; for eighty-four thousand years they governed the kingdom; for eighty-four thousand years they led the holy life in this Makhadeva Mango Grove after shaving off their hair and beard, putting on the yellow robe, and going forth from the home life into homelessness. By developing the four divine abodes, on the dissolution of the body, after death, they passed on to the Brahma-world. "
"Nimi was the last of those kings. He was a righteous king who ruled by the Dhamma, a great king who was established in the Dhamma. He conducted himself by the Dhamma among brahmins and householders, among town-dwellers and country folk, and he observed the Uposatha days on the fourteenth, fifteenth, and eighth of the fortnight. "
"Once, Ananda, when the gods of the Thirty-three had met together and were seated in the Sudhamma Assembly, this discussion arose among them: 'It is a gain, sirs, for the people of Videha, it is a great gain for the people of Videha that their King Nimi is a righteous king who rules by the Dhamma, a great king who is established in the Dhamma. He conducts himself by the Dhamma among brahmins and householders, among town dwellers and country folk, and he observes the Uposatha days on the fourteenth, fifteenth, and eighth of the fortnight.' "
"Then Sakka, ruler of gods, addressed the gods of the Thirty three: 'Good sirs, do you want to see King Nimi?' 'Good sir, we want to see King Nimi.' Now on that occasion, it being the Uposatha day of the fifteenth, King Nimi had washed his head and ascended to the upper palace chamber, where he was seated for the Uposatha observance. Then, just as quickly as a strong man might extend his flexed arm or flex his extended arm, Sakka, ruler of gods, vanished among the gods of the Thirty-three and appeared in the presence of King Nimi. He said: 'It is a gain for you, great king, it is a great gain for you, great king. When the gods of the Thirty-three had met together and were seated in the Sudhamma Assembly, this discussion arose among them: "It is a gain, sirs, for the people of Videha...eighth of the fortnight." Great king, the gods want to see you. I shall send a chariot harnessed to a thousand thoroughbreds for you, great king. Great king, mount the divine chariot without misgiving.' "King Nimi consented in silence.
Then, just as quickly as a strong man might extend his flexed arm or flex his extended arm, Sakka, ruler of gods, vanished in the presence of King Nimi and appeared among the gods of the Thirty-three. Then Sakka, ruler of gods, addressed the charioteer Matali thus: 'Come, good Matali, prepare a chariot harnessed to a thousand thoroughbreds, and go to King Nimi and say: "Great king, this chariot harnessed to a thousand thoroughbreds has been sent for you by Sakka, ruler of gods. Great king, mount the divine chariot without misgiving.'"
'"May your words be held sacred," the charioteer Matali replied. And having prepared a chariot harnessed to a thousand thoroughbreds, he went to King Nimi and said: 'Great king, this chariot harnessed to a thousand thoroughbreds has been sent for you by Sakka, ruler of gods. Great king, mount the divine chariot without misgiving. But, great king, by which route shall I drive you: by that on which doers of evil experience the results of evil actions, or by that on which doers of good experience the results of good actions?' King Nimi: 'Drive me by both routes, Matali'
"Matali brought King Nimi to the Sudhamma Assembly. Sakka, ruler of gods, saw King Nimi coming in the distance and said to him: 'Come, great king! Welcome, great king! The gods of the Thirty-three, great king, seated in the Sudhamma Assembly, have expressed themselves thus: "It is a gain, sirs, for the people of Videha...eighth of the fortnight." Great king, the gods of the Thirty-three want to see you. Great king, enjoy divine might among the gods.'
"'Enough, good sir. Let the charioteer drive me back to Mithila. There I will conduct myself by the Dhamma among brahmins and householders, among town-dwellers and country folk; there I will observe the Uposatha days on the fourteenth, fifteenth, and eighth of the fortnight.' "
"Then Sakka, ruler of gods, told the charioteer Matali: 'Come, good Matali, prepare the chariot harnessed to a thousand thoroughbreds and drive King Nimi back to Mithila.' " 'May your word be held sacred,' the charioteer Matali replied. And having prepared the chariot harnessed to a thousand thoroughbreds, he drove King Nimi back to Mithila. And there, indeed, King Nimi conducted himself by the Dhamma among brahmins and householders, among town-dwellers and country folk; and there he observed the Uposatha days on the fourteenth, fifteenth, and eighth of the fortnight. "
"Then at the end of many years, many hundred years, many thousand years, King Nimi addressed his barber thus: ...(as above)...... By developing the four divine abodes, on the dissolution of the body, after death, he passed on to the Brahma-world. Now King Nimi had a son named Kalarajanaka. He did not go forth from the home life into homelessness. He broke that good practice. He was the last man among them. " "Now, Ananda, it may be that you think thus: 'Certainly, someone else was King Makhadeva on that occasion.' But it should not be regarded thus. I was King Makhadeva on that occasion. I instituted that good practice and later generations continued that good practice instituted by me. But that kind of good practice does not lead to disenchantment, to dispassion, to cessation, to peace, to direct knowledge, to enlightenment, to Nibbana, but only to reappearance in the Brahma-world. But there is this kind of good practice that has been instituted by me now, which leads to complete disenchantment, to dispassion, to cessation, to peace, to direct knowledge, to enlightenment, to Nibbana. And what is that good practice? It is this Noble Eightfold Path; that is, right view, right intention, right speech, right action, right livelihood, right effort, right mindfulness, and right concentration. This is the good practice instituted by me now, which leads to complete disenchantment, to dispassion, to cessation, to peace, to direct knowledge, to enlightenment, to Nibbana. "
"Ananda, I say to you: continue this good practice instituted by me and do not be the last man. Ananda, when there are two men living, he under whom there occurs a breach of this good practice - he is the last man among them. Therefore, Ananda, I say to you: continue this good practice instituted by me and do not be the last man."
That is what the Blessed One said. The venerable Ananda was satisfied and delighted in the Blessed One's words.
In summary, the Buddha was living in Mithila in the Makhādeva mango grove and at a certain spot he smiles. In reply to Ananda's question on why he smiled, he tells him the story of King Makhādeva (his past life), of how he renounced the world when he was old and became a recluse, enjoining on his eldest son to do likewise when the time came. King Makhādeva developed the four Brahmavihārā and was reborn in the Brahma world.
Eighty four thousand of his descendants, in unbroken succession, followed the tradition set by him; the last of the kings to do this was king Nimi, and his virtue having been remarked by the gods of the thirty-three , Sakka the ruler of gods invited him there. King Nimi accepted the invitation, but later returned to earth to rule righteously and to observe the four fast days in each month. King Nimi's son was Kālārajanaka, who broke the tradition set by his ancestors and proved the last of the line.
Buddha told Ananda that King Makhādeva's tradition only led one to the Brahma world, but the teachings of the Buddha lead to Enlightenment and Nibbāna. The path to Nibbana is the noble eightfold path. He used this story to inspire Ananda not to be the last of the line to live by the Eightfold Path.
References: 1. www.accesstoinsight.org 2. https://suttacentral.net/ 3. The middle length discourses of the Buddha (Bhikkhu Bodhi)