Philippine president Rodrigo Duterte has ordered his troops to crush militants who are fighting street battles with government forces in the south, warning that the country is at grave risk of "contamination" by Islamic State (IS).
The city of Marawi, home to some 200,000 people, has been under siege by IS-linked militants since a government raid on Tuesday night on a suspected hideout of Isnilon Hapilon, who is on Washington's list of most-wanted terrorists.
After the raid failed, gunmen swept through the streets, fending off government forces and taking over large parts of the city.
Mr Duterte imposed martial law on the southern third of the nation earlier this week as the fighting continued.
At least 44 people have died, including 31 militants and 11 soldiers. It is not immediately clear whether civilians are among the dead.
The violence has forced thousands of people to flee and raised fears of growing extremism.
Mr Duterte told soldiers in Iligan, a city near Marawi, that he had long feared that "contamination by IS" loomed in the country's future. "You can say that IS is here already," he said.
He gave his troops a free hand to wrest control of Marawi, saying: "You can arrest any person, search any house without warrant."
The president has previously allowed extra-judicial killings of thousands of people in his crackdown on illegal drugs.
However, he has also offered dialogue to militants who are not on the streets fighting.
"We can still talk about it," Mr Duterte said. "But those who are out-and-out terrorists, and you cannot be convinced to stop fighting - so be it. Let us fight."
Hapilon is still hiding out in the city under the protection of gunmen who are trying to find a way to extricate him, the country's military chief said.
"Right now, he is still inside (the city)," General Eduardo Ano said.
"We cannot just pinpoint the particular spot."
He said Hapilon suffered a stroke after a government air strike wounded him in January.
Gen Ano predicted that the military operation will take about a week as soldiers go house-to-house to clear the city of militants.
"We will make this their cemetery," he said. "We have to finish this."
In a sign that the long-standing problem of militancy in the south could be expanding, Solicitor General Jose Calida said foreigners are fighting alongside the gunmen in Marawi, including Indonesians and Malaysians.
Gen Ano also said foreign fighters are believed to be inside, but he was more cautious. "We suspect that, but we're still validating," he said.
With much of Marawi a no-go zone, confusion reigned. One local police chief has told reporters that he is fine - two days after Mr Duterte announced he had been beheaded by militants.
Police chief Romeo Enriquez said there may have been confusion because his predecessor in Malabang, a town near Marawi, was killed in the fighting on Tuesday, although he was not beheaded. Mr Enriquez has been in the job for about two months.
Witnesses said gunmen were flying the black flags of IS.
Authorities are working to determine the condition of a Catholic priest and worshippers who were taken hostage by gunmen earlier this week.
Hapilon, an Islamic preacher, is a commander of the Abu Sayyaf militant group who pledged allegiance to the Islamic State group in 2014.
He also heads an alliance of at least 10 smaller militant groups, including the Maute, which have a heavy presence in Marawi and were instrumental in fighting off government forces in this week's battles.
All of the groups are inspired by the Islamic State group, but so far there is no sign of significant, material ties.
Washington has offered a five million dollar reward for information leading to Hapilon's capture.
The southern Philippines has been troubled by decades-long Muslim separatist uprisings in the predominantly Catholic nation. But recent attacks and this week's siege suggest the threat of extremist ideology may be growing.