The siege of Marawi has finally come to an end after one final fierce gunfight with a group of militants holed up in the shattered city. Defence Secretary Delfin Lorenzana announced that five months combat operations in Marawi have ended. "There are no more militants inside Marawi City," he said.

On Sunday (22 October), Philippine troops were battling the remaining militants from the Isis-linked Maute group who refused to surrender and appeared ready to fight to the death. Artillery and automatic gunfire were still heard on Monday and Reuters journalists saw flames erupt behind a mosque.

Marawi Philippines
Flame rises as government troops clear the area of pro-Islamic State militants Romeo Ranoco/Reuters

The bodies of 40 fighters and two of their wives were found there and in two buildings close by. It was not immediately clear how the suspected militants had died but it's possible some committed suicide after they were cornered by troops, an official said.

At least 1,780 of the hostages seized by the militants, including a Roman Catholic priest, were rescued. The final group of 20 captives were freed overnight, Colonel Romeo Brawner said at a news conference. That left the gunmen with none of the hostages they had used as human shields to slow the military advance for months.

The authorities said 920 militants, 165 troops and police and at least 45 civilians were killed in the conflict, which displaced more than 300,000 people.

Troops have started a phased withdrawal and the authorities may soon allow some residents to return to homes not damaged by the fighting.

The centre of the once picturesque lakeside town is now in ruins after heavy shelling and aerial bombing. The government estimates the rebuilding of the heart of Marawi could cost in excess of $1 billion (760m).

Duterte had declared Marawi liberated six days ago, even though fighting was not actually over. On Sunday, he said it was important to be vigilant because no country could escape Islamic State's "clutches of evil". He said: "I'm not trying to scare you, but let's just be prepared for any event."

The rebel occupation stunned a military inexperienced in urban combat and stoked wider concerns that Islamic State loyalists have gained influence among local Muslims and have ambitions to use the island of Mindanao as a base for operations in Southeast Asia. Those fears are compounded by the organisation of the militant alliance and its ability to recruit young fighters, lure foreign radicals, stockpile huge amounts of arms and endure 154 days of ground offensive and air strikes.

Ernesto Abella, spokesman for President Rodrigo Duterte, said the Philippines had prevailed against "the most serious threat of violent extremism and radicalism in the Philippines and in Southeast Asia". Defence Secretary Delfin Lorenzana said the security forces had "nipped the budding infrastructure" of extremist groups. "In crushing thus far the most serious attempt to export violent extremism and radicalism in the Philippines and in the region, we have contributed to preventing its spread in Asia," Lorenzana said.