Harishchandra promises Varuna the son he asks for and keeps putting off the sacrifice; the prince flees, the king swells with disease, and the bought boy Shunahshepa praises the gods from the post until his bonds fall.
Harishchandra, sonless, vows to Varuna to sacrifice the son he is granted, then delays five times. Rohita refuses and wanders six years, urged on yearly by Indra in human form, while Varuna afflicts the king with a swollen belly. Rohita buys Shunahshepa from the starving Ajigarta for a hundred cows; the father takes two more hundreds to bind and to slay him. The boy turns to the gods one after another with the verses of Rigveda 1.24-30; as he praises Ushas the bonds fall and the king is healed. He chooses Vishvamitra as father and is named Devarata; the elder fifty sons of Vishvamitra are cursed, the younger fifty blessed.
The hymns ascribed to Shunahshepa ask Varuna to loosen the upper, middle and lower bond. Two verses name him: fettered, bound to three pillars, he called on the Aditya, and the singer asks Varuna to release 'us' as he released him. A hymn to Agni says Agni loosed Shunahshepa, bound for a thousand, from the stake.
What is different here:
No king, no prince, no vow, no father with a knife; only the bound man, the prayer and the release. In 5.2.7 the releaser is Agni.
Indra carries off King Ambarisha's sacrificial victim and the priest demands the animal or a man. The king finds the sage Richika on Bhrigutunga; the father will not sell the eldest nor the mother the youngest, and the middle son Shunahshepa offers himself. Resting at Pushkar the boy begs his uncle Vishvamitra for help. Vishvamitra's sons refuse to take his place and are cursed; he teaches the boy two hymns. Bound to the post in red, the boy praises Agni and Indra; Indra grants him long life and the king still gains the fruit of the rite.
What is different here:
Ambarisha for Harishchandra, Richika for Ajigarta; no vow to Varuna, no Rohita, no disease; the boy volunteers; Vishvamitra is his uncle and acts before the rite; Indra frees him. Set at Pushkar.
Harishchandra obtains Rohita from Varuna on the promise of sacrificing him and delays stage by stage. Rohita goes to the forest with his bow; hearing his father has dropsy he tries to return but Indra turns him back for five years. In the sixth he buys Shunahshepa, Ajigarta's second son. Vishvamitra, Jamadagni, Vasishtha and Ayasya are the priests; Indra gives the king a golden chariot.
What is different here:
Follows the Aitareya closely but names the illness as dropsy and gives the golden chariot to the king, not the boy; the boy's release is told elsewhere in the same canto.
Varuna, cheated again and again, curses Harishchandra with dropsy. At the sacrifice Vishvamitra pities the weeping Shunahshepa and gives him a mantra of Varuna to repeat in his mind. Varuna appears before the assembly; the king confesses, and Varuna orders the boy released, declares the sacrifice complete and cures the king.
What is different here:
Varuna explicitly curses the king, appears in person and himself frees the boy; a single Varuna mantra replaces the chain of Vedic hymns.
In a list of Vishvamitra's deeds Bhishma recalls that Shunahshepa, son of Richika, was about to be slain as the victim in Ambarisha's great sacrifice and was delivered through Vishvamitra, and that the fifty sons who would not honour Devarata as eldest were cursed.
What is different here:
An allusion only; agrees with the Ramayana on Richika and Ambarisha but keeps the Brahmana's Devarata and the cursed sons.
Sources: Rigveda Brahmanas: the Aitareya and Kausitaki Brahmanas, tr. A. B. Keith (1920); Hymns of the Rigveda, tr. R. T. H. Griffith (1896), hymns read for the Vedic layer; The Ramayan of Valmiki, tr. R. T. H. Griffith (1870-74); Srimad-Bhagavatam (Bhaktivedanta Vedabase); The Srimad Devi Bhagawatam, tr. Swami Vijnanananda (1921-22); The Mahabharata, tr. K. M. Ganguli (1883-96), sections read for the Vedic layer