For when Joshua and the Israelites saw that the ambush group had captured the town, and that smoke was rising from it, they turned around and attacked the men of Ai.
Joab realized he would have to fight both in front of him and behind him, so he chose some of Israel's best troops and he took charge of them to lead the attack against the Arameans.
Adoni-zedek, king of Jerusalem, learned that Joshua had captured Ai and destroyed the town completely, as he had also done to Jericho, and had killed its king, just as he had the king of Jericho. He also heard that the Gibeonites had made peace with the Israelites and were allied with them.
When the men of Ai looked back they saw the smoke rising up into the sky from the town. They had nowhere to run to, because the Israelites who had been running away towards the wilderness now turned on their pursuers.
The men from the ambush also came from the town and attacked them, so they were caught in the middle, with the Israelites on both sides. The Israelites cut them down—not a single man survived or got away.