DAMASAK, Nigeria — Boko Haram’s black flag is everywhere in the town of Damasak, deep in Islamist-held territory in northern Nigeria: It is painted on former administrative buildings and schools, and on the side of abandoned gas stations.

The other unmistakable sign of the Islamist militants’ recent presence is that very few residents remain in a once-thriving town of 200,000. They have either fled to the state capital, Maiduguri, or been killed by Boko Haram. Every looted and battered storefront yawns open to the dusty roadside.

Mostly, the only sound in the hot, still air is from military vehicles, carrying soldiers from the neighboring countries of Chad and Niger as they make their way through the wreckage of the deadly five-month Islamist occupation of this Nigerian town. From time to time, the Chadian soldiers ululate to celebrate their victory against the militants in a fierce firefight that stretched into last week.