In the Tirthayatra Parva of Mahabharata, the story of sage Agastya and how he dries up the oceans by drinking all their water is narrated. This story follows that one to explain how the oceans were filled with water again.
In olden times a king named Sagara was born in the Ishkvasu dynasty. He was very strong, and powerful, and had two wives but no sons. He wanted a son very much and did penance on Mount Kailasa for a long time, and pleased Lord Shiva.
Shiva appeared before him, and said that I am happy with you, and you will soon have sons. Because of the time you have asked for this boon (astrological significance) one of your wives will have 60,000 sons, and the other one will have 1 son. All of the 60,000 sons will be destroyed at the same time but your lineage will be continued by the grandson from the wife who will have one son.
Both his queens got pregnant in due time; queen Vaidarbhi gave birth to a gourd, and queen Shaibya to a son.
The king was about to throw the gourd but a voice from the sky told him to take the seeds from the gourd, and preserve them in a vessel partly filled with warm ghee. He did as told, and soon 60,000 sons were born from the seeds.
His sons were numerous, and powerful and due to their strength they caused havoc and oppressed everyone including the gods.
One day King Sagara decided to do an Ashvamedha sacrifice, and released the horse. This horse was lost at the edge of the now dried ocean, and his sons returned to tell him this news. He was angry at hearing the news and told them not to return till they found the horse.
The sons were hell bent on finding the horse, and went to great lengths to find it and caused destruction along the way. Finally, they noticed a hole in the earth where the ocean had dried up, and then went inside the hole to eventually the reach the lowest of the nether regions known as Patala.
They searched for the horse in patala, and saw that the horse was next to the powerful sage Kapila. The brothers charged towards sage Kapila in order to retrieve the horse and punish him, but when the sage’s meditation was broken, and he opened his eyes all the brothers were burned to ashes instantly.
Narad saw all this and went to King Sagar and told him what happened. King Sagar was extremely remorseful and told his grandson Anshuman who was Asamanja’s son who was the only son of Shaibya that because of Sagara’s greed his 60,000 sons have been killed, and he has already abandoned his other son Asamanja.
At this, Yudhisthar asks sage Lomasha who is narrating this story why Sagara abandoned Asamanja.
Lomasha tells him that Asamanja used to grasp the weak and crying infants of the citizens by the neck and throw them in the river. The citizens went to the king to complain against Asamanja and Sagara decided to expel him from the country.
Back to the main story, Sagara now wants Anshuman to go retrieve the horse because he is very miserable at not being able to complete the sacrifice.
Ashuman goes to the place where the earth has been torn apart, enters the ocean and reaches patala where sage Kapila is present.
He bows down to the sage and Kapila tells him that he is very happy with him, and tells him to ask for a boon. Anshuman first asks him for the horse, and then he asks him for water to purify his uncles.
The text in the story is not immediately clear here, but you later realize that in fact he is asking for Gangajal and what has happened is that along with the oceans the rivers have probably also dried up or maybe they equated Ganga to an ocean as well.
Regardless, Kapila gives him the horse, and gives him the blessing that Anshuman’s grandson will bring down the “three-coursed one” from heaven. The three coursed one is the river Ganga which flows on heaven, earth, and nether regions, and is therefore three coursed.
In due course Bhaghirath is born who is to fulfill this destiny, and he did penance for a thousand years to please Ganga. The river Ganga personified shows herself to him, and asks him what he wants. He tells her that his 60,000 uncles cannot go to heaven till the time they are sprinkled with her water, and asks her to descend on the earth so their souls can be freed, and they can go to heaven.
Ganga tells him that she is happy with him and that she will descend down on the earth to do as he wishes. However, the earth will not be able to sustain her force if she descends directly on the earth, and he must please Lord Shiva so that he gives permission for the river Ganga to fall down on his head and sustain the pressure from the falls so that the earth may be spared.
Bhaghirath then goes to Mount Kailasa and prays to Lord Shiva for a thousand years, and Lord Shiva shows himself and says that he will bear the fall of the great Ganga when she descends from the heavens.
The river Ganga falls on the head of Lord Shiva, and then reaches earth, and asks Bhaghiratha to show him the way where he wants her to flow. Bhaghiratha takes her to the ocean where his ancestors died and thus they are purified and reach heaven, and the oceans are also populated with water again!