When Athaliah, Ahaziah's mother, learned of her son's death, she immediately destroyed the entire royal family.
But Jehosheba, King Jehoram's daughter and Ahaziah's sister, secretly took Ahaziah's son Jehoash from the rest of the royal children who were about to be murdered and hid him in a bedroom along with his nurse. In this way Jehoash was hidden from Athaliah and wasn't murdered.
He remained hidden with his nurse in the LORD's temple for six years while Athaliah ruled the country.
But in the seventh year Jehoiada sent for the commanders of the Carites and of the guards and had them come to him at the LORD's temple. He made a covenant with them, and made them swear a solemn pledge in the LORD's temple. Then he showed them the king's son.
He commanded them, "This is what you must do: A third of you coming on sabbath duty will guard the palace,
a second third will be at the Sur Gate, and the final third will be at the gate behind the guards. You will take turns guarding the temple.
You who are in the first two groups that usually go off duty on the Sabbath should also guard the LORD's temple to protect the king.
Surround the king completely, each of you with your weapons drawn. Whoever comes near your ranks must be killed. Stay near the king wherever he goes."
The unit commanders did everything that Jehoiada the priest ordered. They each took charge of those men reporting for duty on the Sabbath as well as those going off duty on the Sabbath. They came to the priest Jehoiada.
Then the priest gave the unit commanders King David's spears and shields, which were kept in the LORD's temple.
The guards, each with their weapons drawn, then took up positions near the temple and the altar, stretching from the south side of the temple to the north side to protect the king. Everyone was holding his weapons, surrounding the king.
Jehoiada then brought out the king's son, crowned him, gave him the royal law, and made him king and anointed him, as everyone applauded and cried out, "Long live the king!"
When Athaliah heard the noise made by the guard and the people, she went to the people at the LORD's temple
and saw the king standing by the royal pillar, as was the custom, with the commanders and trumpeters beside the king. All the people of the land were rejoicing and blowing trumpets. Athaliah ripped her clothes and screamed, "Treason! Treason!"
Then the priest Jehoiada ordered the unit commanders who were in charge of the army: "Take her out under guard," he told them, "and kill anyone who follows her." This was because the priest had said, "She must not be executed in the LORD's temple."
They arrested her when she reached the entrance of the Horse Gate at the royal palace. She was executed there.
Jehoiada then made a covenant between the LORD, the king, and the people, that the people would belong to the LORD. The king and the people also made a covenant.
Then all the people of the land went to Baal's temple and tore it down, smashing its altars and images into pieces. They executed Mattan, Baal's priest, in front of the altars. The priest Jehoiada posted guards at the LORD's temple.
Then he took the unit commanders, the Carites, the guards, and all the people of the land, and they led the king down from the LORD's temple, processing through the Guards' Gate to the palace, where the king sat upon the royal throne.
All the people of the land rejoiced, and the city was at peace now that Athaliah had been executed at the palace.
Jehoash was 7 years old when he became king.