GAO, Mali — Aguissa Ag Badara, a former tour guide, now rides around the city on the back of a motorcycle looking for Islamist militants who may still be lurking about. He even wears a pin to advertise his mission. It reads, “Vigilance Brigade: Patrollers of Gao.”

“We said Mujao had infiltrated the population, but no one listened,” said Mr. Ag Badara, referring to the Islamist militants who attacked this strategic city last week. “We support the French, we support the Malian state and the African forces, but why are they only at the checkpoints and in their camps? The war is here in the streets.”

The battle for Mali is not over. Remnants of the militant forces that once controlled major towns have not simply burrowed into their rugged, mountain hideaways far to the north. They also appear to have taken refuge in smaller villages nearby, essentially pulling back to less-contested ground after the French-led intervention to oust them, residents and experts say.

That infiltration, in a string of neighboring villages along the Niger River, is what enabled last Sunday’s attack in the heart of Gao, a town of about 86,000 whose reconquest was a pivotal part of the French offensive last month. For hours, bullets flew as jihadists from around Gao pinned down French and Malian forces.