When Athaliah the mother of Ahaziah saw that her son was dead, she arose and destroyed all the royal heirs.
But Jehosheba, the daughter of King Joram, sister of Ahaziah, took Joash the son of Ahaziah, and stole him away from among the king's sons who were being murdered; and they hid him and his nurse in the bedroom, from Athaliah, so that he was not killed.
So he was hidden with her in the house of the Lord for six years, while Athaliah reigned over the land.
In the seventh year Jehoiada sent and brought the captains of hundreds--of the bodyguards and the escorts--and brought them into the house of the Lord to him. And he made a covenant with them and took an oath from them in the house of the Lord, and showed them the king's son.
Then he commanded them, saying, "This is what you shall do: One-third of you who come on duty on the Sabbath shall be keeping watch over the king's house,
one-third shall be at the gate of Sur, and one-third at the gate behind the escorts. You shall keep the watch of the house, lest it be broken down.
The two contingents of you who go off duty on the Sabbath shall keep the watch of the house of the Lord for the king.
But you shall surround the king on all sides, every man with his weapons in his hand; and whoever comes within range, let him be put to death. You are to be with the king as he goes out and as he comes in."
So the captains of the hundreds did according to all that Jehoiada the priest commanded. Each of them took his men who were to be on duty on the Sabbath, with those who were going off duty on the Sabbath, and came to Jehoiada the priest.
And the priest gave the captains of hundreds the spears and shields which had belonged to King David, that were in the temple of the Lord.
Then the escorts stood, every man with his weapons in his hand, all around the king, from the right side of the temple to the left side of the temple, by the altar and the house.
And he brought out the king's son, put the crown on him, and gave him the Testimony; they made him king and anointed him, and they clapped their hands and said, "Long live the king!"
References for 2 Kings 11:12
Now when Athaliah heard the noise of the escorts and the people, she came to the people in the temple of the Lord.
When she looked, there was the king standing by a pillar according to custom; and the leaders and the trumpeters were by the king. All the people of the land were rejoicing and blowing trumpets. So Athaliah tore her clothes and cried out, "Treason! Treason!"
And Jehoiada the priest commanded the captains of the hundreds, the officers of the army, and said to them, "Take her outside under guard, and slay with the sword whoever follows her." For the priest had said, "Do not let her be killed in the house of the Lord."
So they seized her; and she went by way of the horses' entrance into the king's house, and there she was killed.
Then Jehoiada made a covenant between the Lord, the king, and the people, that they should be the Lord's people, and also between the king and the people.
And all the people of the land went to the temple of Baal, and tore it down. They thoroughly broke in pieces its altars and images, and killed Mattan the priest of Baal before the altars. And the priest appointed officers over the house of the Lord.
Then he took the captains of hundreds, the bodyguards, the escorts, and all the people of the land; and they brought the king down from the house of the Lord, and went by way of the gate of the escorts to the king's house. Then he sat on the throne of the kings.
So all the people of the land rejoiced; and the city was quiet, for they had slain Athaliah with the sword in the king's house.
Jehoash was seven years old when he became king.