Joshua 8:12-22 NIV
Joshua had taken about five thousand men and set them in ambush between Bethel and Ai, to the west of the city. So the soldiers took up their positions—with the main camp to the north of the city and the ambush to the west of it. That night Joshua went into the valley.
When the king of Ai saw this, he and all the men of the city hurried out early in the morning to meet Israel in battle at a certain place overlooking the Arabah. But he did not know that an ambush had been set against him behind the city. Joshua and all Israel let themselves be driven back before them, and they fled toward the wilderness. All the men of Ai were called to pursue them, and they pursued Joshua and were lured away from the city. Not a man remained in Ai or Bethel who did not go after Israel. They left the city open and went in pursuit of Israel.
Then the LORD said to Joshua, “Hold out toward Ai the javelin that is in your hand, for into your hand I will deliver the city.” So Joshua held out toward the city the javelin that was in his hand. As soon as he did this, the men in the ambush rose quickly from their position and rushed forward. They entered the city and captured it and quickly set it on fire.
The men of Ai looked back and saw the smoke of the city rising up into the sky, but they had no chance to escape in any direction; the Israelites who had been fleeing toward the wilderness had turned back against their pursuers. For when Joshua and all Israel saw that the ambush had taken the city and that smoke was going up from it, they turned around and attacked the men of Ai. Those in the ambush also came out of the city against them, so that they were caught in the middle, with Israelites on both sides. Israel cut them down, leaving them neither survivors nor fugitives.
NIV: New International Version