MARAWI, Philippines — After she heard the first few shots ring out a week ago in Marawi, the center of Islamic faith in this predominantly Christian nation, Jemaliah Batingulo said she locked all the doors to keep her five children safe inside.

But when young masked men with long rifles barged into nearby homes and began shooting non-Muslims, she said, she grabbed her children and quickly escaped. Minutes later, she saw her wooden house burst into flames.

“There was gunfire everywhere,” Ms. Batingulo, 36, said on Tuesday. “We all started running and running until the edge of town. We didn’t have any food, just water we grabbed before fleeing.”

Ms. Batingulo was one of thousands of people forced to flee the onslaught of militants loyal to the Islamic State that has convulsed this city of 200,000, prompting President Rodrigo Duterte to impose martial law on the southern Philippines and posing a major challenge to his government.