At the climax of the battle, a sophisticated military tactic unfolds flawlessly, leaving the enemy forces trapped with no route of escape. As the trap is sprung, a group emerges from the city. The primary approach among commentators is that this refers to the Israelite ambush force. After setting the city ablaze, these soldiers marched out to confront the men of Ai, who were desperately trying to flee back to their homes [רש״י, מצודת דוד, מלבי״ם]. Conversely, another perspective suggests that it was the men of Ai themselves who had initially marched out of the city, only to suddenly realize they were flanked on both sides by the Israelite army [ביאור שטיינזלץ].
Regardless of who was emerging from the gates, the result was exactly the same: the men of Ai were caught directly in the middle [מצודת ציון]. This situation highlights Joshua's military brilliance in ensuring the enemy was surrounded from every possible direction. His main camp blocked any escape to the north and west, while the ambush force confronted them from the south. Even the eastern route offered no safety, as it led directly toward Jericho, a territory already conquered and firmly under Israelite control [מלבי״ם].
Caught in this inescapable trap, the enemy faced a combined assault that ended in their absolute destruction. The forces of Ai were entirely wiped out, leaving behind not a single survivor or refugee [מצודת ציון].