Josiah starts reigning as an eight-year-old boy and rules for thirty-one years.
Departing radically from the ways of his dad and granddad, Josiah becomes a great and righteous king, doing everything that David himself would have done.
In the eighteenth year of his reign, Josiah sends his secretary Shaphan to ask the priest Hilkiah to use the donations made at the Temple for repairs on it.
Hilkiah tells Shaphan that he's found "the book of the law" (probably a version of Deuteronomy), and gives it to Shaphan, who reads it.
Shaphan tells Josiah that they're paying the workers for the repairs. Then he reads him the book of the law they've discovered.
Josiah is distressed, realizing how far they've departed from the Laws of Moses. He tears his clothes.
Chatting with Huldah
Believing that God's wrath is against them for not following these rules, Josiah sends Shaphan, Hilkiah, and a few others to ask God what they should do.
They go to a prophetess named Huldah (the wife of the son of the wardrobe keeper). She says that God will, indeed, visit his wrath on the people for their sins, just as the book of the law says he will.
But, she says, God will have mercy on Josiah, since he humbled himself before God and repented for the idolatrous sins he committed in ignorance. He'll die and be laid in his grave in peace. He won't see the destruction that's coming for Judah.