MARAWI, Philippines — Militants loyal to the Islamic State stubbornly resisted as government troops pushed on Monday to drive them out of Marawi, a city in the southern Philippines where hundreds of desperate residents remained trapped by the fighting.

Troops have so far cleared about half the city of militants from the Abu Sayyaf and Maute groups and the foreign fighters backing them, but the insurgents have broken up into small groups and have proved elusive, according to Zia Alonto Adiong, a spokesman for the Lanao del Sur provincial government.

The military’s struggle to drive out the rebels has become a major challenge for the government of President Rodrigo Duterte, who declared martial law in the region last week and vowed to defeat the insurgents.

There were signs that the battle was turning into a siege. Mr. Alonto said the province had imposed a nightly curfew and called on civilians to help the military fight and subdue the militants.