Philippine President Rodrigo Duterte has appealed to Islamist militants to abandon hostilities and start dialogue in an effort to end their bloody occupation of a southern city that experts called a major blow to regional security.
Mr Duterte said the presence of foreign fighters in street battles that have raged since Tuesday in Marawi City was proof that Islamic State (IS, also known as ISIS) had gained a foothold on the restive island of Mindanao, but there was still a chance for peace.
"You can say that the ISIS is here already," Mr Duterte told soldiers in nearby Iligan City, referring to Islamic State.
"My message mainly to the terrorists on the other side is we can still solve this through dialogue. And if you cannot be convinced to stop fighting, so be it. Let's just fight."
Special forces commandoes were deployed to drive out the remaining 20 to 30 Maute group rebels holed-up in Marawi but encountered heavy resistance on Friday. The army said 11 soldiers and 31 militants have been killed.
Fighting erupted on Tuesday after a bungled raid by security forces on a Maute hideout, which spiralled into chaos, with gunmen seizing bridges, roads and buildings and taking Christians hostage. Mr Duterte responded by declaring martial law throughout his home island of Mindanao.
Rohan Gunaratna, a Singapore-based security expert, said the siege was a wake-up call for the Philippines.
"Islamic State capturing a major city in the Philippines is a very significant blow to the security and stability of this region," he said.
"The Filipinos need to get their act together... They must understand the truth that IS ideology took hold in their country. The local groups have transformed."
Malaysians, Indonesians and other foreigners were among the guerrillas killed on Thursday, which the government said demonstrated how the Philippines could become a haven for overseas militants.
The White House on Thursday said it backed the Philippine fight against "cowardly terrorists".
Mr Duterte has warned of "contamination" by Islamic State, exploiting the poverty, lawlessness and porous borders of predominantly Muslim areas of Mindanao island to establish a base for radicals from southeast Asia and beyond.
He has pleaded with political and Islamic leaders to keep foreign and local militants at bay. Months of air and ground offensives in Mindanao have not dented their resolve.
"What's happening in Mindanao is no longer a rebellion of Filipino citizens," Solicitor General Jose Calida told reporters in explaining why martial law was imposed.
"It has transmogrified into invasion by foreign terrorists, who heeded the call of the ISIS to go to the Philippines if they find difficulty in going to Iraq and Syria."