Updated: Dec 9, 2022
King Bhagiratha, of the Ikshvaku dynasty (the same one which Lord Rama belonged to), managed to please Brahma after successfully completing a stringent penance. He implored Brahma to request goddess Ganga to descend to the earth from heaven in the form of a river, at his behest. He was suggested this as the only way to free the souls of his 60,000 ancestors who had died many years ago due a curse put on them by sage Kapila for a mistake they had committed.
Although Ganga agreed to come down to earth, Brahma mentioned that earth would not be able to withstand the might of the gigantic river, and would be drowned in her waters.
This is where Shiva stepped in. He advised Ganga to fall on his head first, before reaching the earth. This way, Shiva's matted hair helped tame the mighty force of Ganga and allowed a gentler flow to eventually reach the earth.