Imagine this:
You are a young king of a small country. Your northern neighbor, which worshiped the same god as you, has been conquered by a powerful empire, and its people dispersed. Your country is vulnerable and you desperately want to prevent the same fate from being yours. You consult religious leaders but they have no more answers than you have.
You decide to appease your god by collecting a tax and beginning much-needed, extensive repairs on the temple of your god. While the repairs are being made, the high priest comes to you, and brings a scroll found in the temple walls. They then take it to a prophetess to ascertain that the scroll is genuine, and she authenticates it. As king, you then read the scroll. It is polemic, recording laws and history as well as admonitions not to follow the rituals of other gods.
The year is 622 BCE and your name is Josiah. Josiah's story is told in II Kings, chapters 22 and 23.
He responded to the scroll of teaching by making a purge on all the places where his god is worshiped outside the holy temple, and of those places where other gods are worshiped. He is so zealous that he is permitted to die in battle rather than live to see his country conquered and its temple destroyed.
Almost all scholars agree that the scroll presented to Josiah was some form of the book of Deuteronomy, and that it was probably written contemporaneously with the described events and attributed to Moses.