King Sagara performed the Ashvamedha sacrifice to declare his sovereignty over the neighbouring kingdoms. The 60,000 sons of Sagara were following the horse when they saw it enter a cavern where the sage Kapila was meditating. Not seeing the horse, they presumed that Kapila had hidden it.
They did not kill Kapila as he was a sage but they started disturbing his meditation. Annoyed at being disturbed, Kapila, with a curse burnt the 60,000 sons of Sagara. Time passed and later Bhagiratha, the great grandson of Sagara, chanced to come across the bones of his dead ancestors. He wanted to perform the shraddha of his ancestors but there was no water available for the ceremony.
Bhagiratha prayed to Brahma who asked him to pray to Vishnu, to allow the heavenly Ganga to come down to earth. Lord Vishnu asked him to request Shiva, to allow the torrential rain to fall on his head before it came to the earth as the river was very forceful and if allowed to come down unchecked, her fall would split the earth.
Shiva agreed to take the gigantic weight of the cascading Ganga on the matted hair piled high on his head. This ensnared and delayed the progress of the river which, in meandering through the labyrinth of his hair, lost its force and then gently descended to the Himalayas from whence it flowed to the plains bestowing its waters on the parched earth.