MOGADISHU, Somalia — Members of the Shabab, a militant Islamist group, are withdrawing from a strategic town on Somalia’s southern coast as government forces and African Union troops advance toward it, witnesses and residents said Saturday.

Hundreds of civilians have been fleeing the town, Barawe, fearing that they would be caught in the crossfire if fighting breaks out, said one resident, a mother of two who gave only her last name, Abdalla.

“All those who can afford to leave are already gone, and we face constant fears about where to seek refuge if the town comes under attack,” Mrs. Abdalla said. “Only God knows if we will survive.”

Another resident, who asked to remain anonymous because of the uncertainty of the situation, said that some of the Shabab’s armored vehicles had been leaving the town in recent days, but that it was not clear where they were headed.