Militants fighting under the black flag of the Islamic State group have turned a southern city into a battleground, and triggered warnings by President Rodrigo Duterte of a potential IS caliphate.
The violence is the latest in four decades of conflict across the southern third of the mostly Catholic Philippines, where a Muslim separatist rebellion has claimed more than 120,000 lives.
Here is what we know about the latest violence, the factors behind it and what will happen next:
Who are the militants?
They mostly belong to the Maute group, which the government estimates has about 260 armed followers. It is one of a number of hardline groups that split from the nation’s biggest Muslim rebel organisation in anger at a planned peace accord.
The Maute gunmen were protecting Isnilon Hapilon, a leader of a kidnapping-for-ransom gang called the Abu Sayyaf that is also believed to have only a few hundred gunmen but is blamed for the nation’s worst terrorist attacks.
The Maute and Hapilon’s faction of the Abu Sayyaf have pledged allegiance to IS and want to establish a caliphate for it in the southern Philippines, according to Duterte and security analysts.
IS has named Hapilon, 51, its leader in the Philippines, according to security analysts.
Why did the fighting erupt?
After receiving intelligence reports that Hapilon was hiding in Marawi city, security forces went to arrest him on Tuesday but were taken by surprise when they met massive resistance from Maute gunmen protecting him.
The gunmen went on a rampage through Marawi, even though most of its 200,000 residents are Muslim, flying black IS flags partly to distract the troops but also to provide powerful propaganda images to highlight their cause.
What was the response?
President Rodrigo Duterte ordered a massive assault to kill the militants or drive them out of Marawi. The fighting has claimed the lives of at least 15 security forces and 31 militants, according to the military.
At least two civilians have also been killed, while local media have reported the murders of nine other people apparently caught at a militant checkpoint.
Duterte also imposed martial law across the entire southern region of Mindanao, which is home to 20 million people, to stop what he said was the rising threat of an IS caliphate being established.
What’s the background to the fighting?
The Philippines’ Muslim minority regard Mindanao as their ancestral homeland. Muslims arrived in the Philippines well before the Spanish landed in the 16th Century and imported Catholicism, and Islam was most firmly established in the south.
Heavy Catholic migration in recent decades has made Muslims a minority even in most Mindanao cities.
Muslim rebels launched their separatist rebellion in the 1970s. The two main rebel groups have signed peace accords with the government in exchange for autonomy, although this has yet to be finalised.
The Maute, Abu Sayyaf and other small hardline groups are not interested in negotiating peace and have in recent years looked to IS to help them.
Nevertheless, security analysts regard these groups as lacking the fundamentalist ideology of their IS superiors, and say they are more interested in criminal activities than implementing ultra-strict versions of Sharia law.
What happens next?
Both sides could emerge with victories from the fighting and martial law, according to Julkipli Wadi, a professor of Islamic studies at the University of the Philippines.
Wadi said he expected the militants to scatter after suffering casualties but then regroup, winning from the experience a “badge of honour” that could draw IS fighters fleeing the Middle East battlefields.
Meanwhile, Duterte could claim an immediate victory in clearing Marawi, while using martial law and the security threat to muster support for some of his other political objectives that have lost some public support, according to Wadi.
He said these included amending the constitution to change the form of government.
There are few expectations that martial law could end the deep-rooted problems that have led to the Muslim conflict in the south.
But Wadi also said he did not believe the vast majority of local Muslims supported an IS caliphate, nor the group’s brutal tactics that include mass beheadings of opponents.