Athaliah was the mother of Ahaziah. When she saw that her son was dead, she took over. She began by massacring the entire royal family.
But Jehosheba, daughter of King Joram and sister of Ahaziah, took Ahaziah's son Joash and kidnapped him from among the king's sons slated for slaughter. She hid him and his nurse in a private room away from Athaliah. He didn't get killed.
He was there with her, hidden away for six years in The Temple of God. Athaliah, oblivious to his existence, ruled the country.
In the seventh year Jehoiada sent for the captains of the bodyguards and the Palace Security Force. They met him in The Temple of God. He made a covenant with them, swore them to secrecy, and only then showed them the young prince.
Then he commanded them, "These are your instructions: Those of you who come on duty on the Sabbath and guard the palace, and those of you who go off duty on the Sabbath and guard The Temple of God, are to join forces at the time of the changing of the guard and form a ring around the young king, weapons at the ready. Kill anyone who tries to break through your ranks. Your job is to stay with the king at all times and places, coming and going."
The captains obeyed the orders of Jehoiada the priest. Each took his men, those who came on duty on the Sabbath and those who went off duty on the Sabbath, and presented them to Jehoiada the priest.
The priest armed the officers with spears and shields originally belonging to King David, stored in The Temple of God.
Well-armed, the guards took up their assigned positions for protecting the king, from one end of The Temple to the other, surrounding both Altar and Temple.
Then the priest brought the prince into view, crowned him, handed him the scroll of God's covenant, and made him king. As they anointed him, everyone applauded and shouted, "Long live the king!"
Athaliah heard the shouting of guards and people and came to the crowd gathered at The Temple of God.
Astonished, she saw the king standing beside the throne, flanked by the captains and heralds, with everybody beside themselves with joy, trumpets blaring. Athaliah ripped her robes in dismay and shouted, "Treason! Treason!"
Jehoiada the priest ordered the military officers, "Drag her outside and kill anyone who tries to follow her!" (The priest had said, "Don't kill her inside The Temple of God.")
So they dragged her out to the palace's horse corral; there they killed her.
Jehoiada now made a covenant between God and the king and the people: They were God's people. Another covenant was made between the king and the people.
The people poured into the temple of Baal and tore it down, smashing altar and images to smithereens. They killed Mattan the priest in front of the altar.
He arranged for the officers of the bodyguard and the palace security, along with the people themselves, to escort the king down from The Temple of God through the Gate of the Guards and into the palace. There he sat on the royal throne.
Everybody celebrated the event. And the city was safe and undisturbed - they had killed Athaliah with the royal sword.
Joash was seven years old when he became king.