When Athaliah, Ahaziah's mother, saw that her son was dead, she proceeded to annihilate all the royal heirs.
References for 2 Kings 11:1
Jehosheba, [who was] King Jehoram's daughter and Ahaziah's sister, secretly rescued Joash son of Ahaziah from the king's sons who were being killed and [put] him and his nurse in a bedroom. So he was hidden from Athaliah and was not killed.
Joash was in hiding with Jehosheba in the Lord's temple six years while Athaliah ruled over the land.
References for 2 Kings 11:3
Then, in the seventh year, Jehoiada sent [messengers] and brought in the commanders of hundreds, the Carites, and the guards. He had them come to him in the Lord's temple, where he made a covenant with them and put them under oath. He showed them the king's son
References for 2 Kings 11:4
and commanded them, "This is what you are to do: one third of you who come on duty on the Sabbath are to provide protection for the king's palace.
A third are to be at the Sur gate and a third at the gate behind the guards. You are to take turns providing protection for the palace.
References for 2 Kings 11:6
Your two divisions that go off duty on the Sabbath are to provide protection for the Lord's temple.
You must completely surround the king with weapons in hand. Anyone who approaches the ranks is to be put to death. You must be with the king in all his daily tasks."
References for 2 Kings 11:8
So the commanders of hundreds did everything Jehoiada the priest commanded. They each brought their men-those coming on duty on the Sabbath and those going off duty-and went to Jehoiada the priest.
The priest gave to the commanders of hundreds King David's spears and shields that were in the Lord's temple.
Then the guards stood with their weapons in hand surrounding the king-from the right side of the temple to the left side, by the altar and by the temple.
He brought out the king's son, put the crown on him, gave him the testimony,and made him king. They anointed him and clapped their hands and cried, "Long live the king!"
References for 2 Kings 11:12
When Athaliah heard the noise from the guard [and] the crowd, she went out to the people at the Lord's temple.
As she looked, there was the king standing by the pillar according to the custom. The commanders and the trumpeters were by the king, and all the people of the land were rejoicing and blowing trumpets. Athaliah tore her clothes and screamed "Treason! Treason!"
References for 2 Kings 11:14
Then Jehoiada the priest ordered the commanders of hundreds in charge of the army, "Take her out between the ranks, and put anyone who follows her to death by the sword," for the priest had said, "She is not to be put to death in the Lord's temple."
So they arrested her, and she went out by way of the Horses' Entrance to the king's palace, where she was put to death.
References for 2 Kings 11:16
Then Jehoiada made a covenant between the Lord, the king, and the people that they would be the Lord's people and [another one] between the king and the people.
References for 2 Kings 11:17
So all the people of the land went to the temple of Baal and tore it down. They broke its altars and images into pieces, and they killed Mattan, the priest of Baal, at the altars. Then [Jehoiada] the priest appointed guards for the Lord's temple.
He took [with him] the commanders of hundreds, the Carites, the guards, and all the people of the land, and they brought the king from the Lord's temple. They entered the king's palace by way of the guards' gate. Then Joash sat on the throne of the kings.
All the people of the land rejoiced, and the city was quiet, for they had put Athaliah to death by the sword in the king's palace.
References for 2 Kings 11:20
Joash was seven years old when he became king.
References for 2 Kings 11:21