Government forces have been unable to dislodge the militants despite deploying ground troops and bombing the city of 200,000 people from the air. More than 200 people have been killed, including 24 civilians, 58 soldiers and police officers, and at least 138 militants, according to the Philippine military.
Tens of thousands of civilians have fled, and much of the city center lies in ruins. The military says that it has cleared 90 percent of the city but that militants remain in three neighborhoods in the center. Analysts say the military has less experience fighting on an urban battlefield, where the militants are mixed in with hundreds of civilians.
Mr. Duterte has declared 60 days of martial law for the southern island of Mindanao, which includes Marawi and his hometown, Davao City. He has twice set deadlines for troops to retake Marawi, the country’s largest predominantly Muslim city, but each deadline has passed with the battle still raging.
On Friday, Brig. Gen. Restituto Padilla predicted that the government would retake Marawi by Monday, Philippines Independence Day. On Saturday, 13 Philippine marines were killed in a clash with militants there.
The militants’ seizure of the city, a bold attempt to establish an Islamic State caliphate in Southeast Asia, marks a significant advance for the Middle East-based terrorist group as well as an apparent reordering of the militant threat in the southern Philippines.
For the first time, it puts the Philippines on the map with failed states such as Libya and Afghanistan as places where Islamic State allies have sought to seize territory for a caliphate, giving the group another regional flash point in its effort to spread its influence globally.
The Islamic State has urged fighters who cannot reach Syria to join the jihad in the Philippines instead, said Sidney Jones, director of the Institute for Policy Analysis of Conflict. Fighters from Indonesia, Malaysia, Chechnya, Yemen and Saudi Arabia were among those killed in the battle for Marawi.
Mindanao has long been a hotbed of insurgencies, with numerous armed groups operating outside government control. Until the siege at Marawi, the best-known internationally was Abu Sayyaf, an ostensibly Islamist group that specialized in kidnapping for ransom, nearly single-handedly turning Southeast Asia into the world’s piracy capital, edging out the Horn of Africa.
The Marawi siege also heralds the rise of Isnilon Hapilon, a longtime leader of Abu Sayyaf who had grown more ideologically minded over the years. Last year, Mr. Hapilon, 51, was named by the Islamic State as its emir in Southeast Asia. Previously based on the island of Basilan, he is on the F.B.I.’s list of most-wanted terrorists and the United States has offered a $5 million reward for his capture.
Various factions have come together behind Mr. Hapilon, notably the Maute Group, led by the brothers Omar and Abdullah Maute. Educated in the Middle East, the Mautes are based in the Marawi area and recently accepted Mr. Hapilon’s leadership as emir.
The Mautes are believed responsible for bombing a market in Davao City in September that killed 15.
Mr. Duterte is the first president from Mindanao, and he ran last year as the candidate who could bring peace to the region. The bombing of his hometown may have inspired his angry challenge to the Mautes in December.
“It’s the usual Duterte brand of bravado,” said Roilo Golez, a former national security adviser to President Gloria Macapagal Arroyo, who left office in 2010. “It’s a way of intimidating the opposition. It works most of the time.”
It hasn’t with the Islamists in Mindanao.
After a clash between his military and Abu Sayyaf in April, Mr. Duterte suggested that the way to stop the militants was to eat them. “Make me mad,” he taunted. “Get me a terrorist. Give me salt and vinegar. I will eat his liver.”
In May, the Philippine military got a tip that Mr. Hapilon had arrived in Marawi to join up with the Maute brothers. When soldiers raided the house where Mr. Hapilon was believed to be, hoping to capture him and claim the $5 million reward, they were surprised to find dozens of well armed militants arrayed against them.
A video later recovered by the military and published by The Associated Press shows the militant leaders plotting their takeover of Marawi days before the military learned of Mr. Hapilon’s presence there. Hundreds of fighters who had gathered in preparation for seizing the city quickly put their plan into effect, burning schools and churches, taking hostages and taking over central Marawi.
Mr. Duterte’s declaration of martial law helped lead to the capture of Cayamora Maute, the father of the Maute brothers, along with other family members on Tuesday at a military checkpoint in Davao City. Some fear that the temporary martial law order in Mindanao could be expanded nationwide, an idea Mr. Duterte has openly toyed with so that he could use the military in his antidrug campaign.
“There is a sense of dread and fear that this will build support for martial law,” said Richard Javad Heydarian, a political analyst and author of the forthcoming book “Duterte’s Rise.” “This could strengthen the feeling of isolation by the Muslim minority.”
Muslims make up only about 5 percent of the country’s population over all but a larger proportion, estimated at 20 to 40 percent, on Mindanao.
Historic grievances among the Muslim Moro people there, widespread poverty and large lawless areas have helped create an opportunity for the Islamic State. A peace process pursued by Mr. Duterte’s predecessor, President Benigno S. Aquino III, faltered in 2015 and has remained deadlocked under Mr. Duterte.
“It was not the spread of ISIS in Iraq and Syria that fueled ISIS cells in the Philippines, but the collapse of the peace process,” said Mr. Abuza of the National War College.
The growing threat in the south will most likely compel Mr. Duterte to improve his relations with the United States, a process that had already begun with the election of President Trump.
Mr. Duterte has raged against the United States for daring to criticize his antidrug campaign and, when President Barack Obama was in office, called for a “separation” from Washington. But Mr. Trump has shown a willingness to overlook the killings, and has praised Mr. Duterte for doing an “unbelievable job on the drug problem,” according to a transcript of a call between the two leaders.
Leaders of the Philippines armed forces prevailed on Mr. Duterte not to reduce military cooperation, including a longstanding United States program to provide training, equipment and intelligence to fight terrorism. Since 2001, the United States has maintained a rotating force of 50 to 100 troops in the southern Philippines to combat Abu Sayyaf.
American Special Forces are assisting the Philippine military in Marawi, the United States Embassy said on Friday, although officials would not provide further details.
“Our military relationship with the Philippines remains robust and multifaceted,” said Emma Nagy, a spokeswoman for the embassy in Manila. “U.S. Special Forces have been providing support and assistance in the southern Philippines for many years, at the request of several different Filipino administrations.”
If the battle in Marawi ends on Monday, as the military hopes, the rebellion in the south is still far from over. The audacity of the rebel takeover, even if it ultimately fails, will probably draw recruits from across the region, including members of other Islamist groups still disaffected and dissatisfied with a moribund peace process.
“If Duterte doesn’t deal with that, then this whole problem is going to fester for a very long time,” Mr. Abuza said. The “ungoverned space” on Mindanao, he said, “is a regional security threat, not just a Philippine security threat.”