Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

The Philippines on Monday declared the end of five months of military operations in a southern city held by pro-ISIS rebels, after a fierce and unfamiliar urban war that has marked the country's biggest security crisis in years.

Offensive combat operations were terminated after troops prevailed in what was the last stand against rebel gunmen who clung on inside several buildings in the heart of Marawi, refusing to surrender.

The bodies of 40 of those fighters and two of their wives were found on Monday in two buildings and a mosque in the battle zone. Artillery and automatic gunfire were still heard on Monday and Reuters journalists saw flames behind a mosque.

Military spokesman, Major General Restituto Padilla, confirmed there was still gunfire, but there were "no more terrorists."

Philippine military chief General Eduardo Ano shows images of Islamic militant leaders Isnilon Hapilon (R) and Omarkhayam Maute (L) during a press conference at a military camp in Marawi on the southern island of Mindanao on Oct. 16, 2017. FERDINANDH CABRERA / AFP - Getty Images

Defence Secretary Delfin Lorenzana said in killing off the extremists, the Philippines had "nipped the budding infrastructure and defeated terrorism."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"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 at a meeting of regional defense ministers.

Related: ISIS Recruits Fighters for the Philippines Instead of Syria

The rebel occupation stunned a military inexperienced in urban combat and stoked wider concerns that ISIS loyalists have gained influence among local Muslims andhave ambitions to use the island of Mindanao as a base for operations in Southeast Asia.

Those fears are compounded by the organization of the militant alliance and its ability to recruit young fighters, stockpile huge amounts of arms and endure 154 days of ground offensive and air strikes that have devastated the city.

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.

The center of the picturesque lakeside town is now in ruins due to heavy shelling and aerial bombing.

After months of slow progress, the military has made significant gains in retaking Marawi in the week since Isnilon Hapilon, ISIS' "emir" in Southeast Asia and Omarkhayam Maute, a leader of the Maute militant group, were killed in a nighttime operation. Another leader and possible bankroller of the operation, Malaysian Mahmud Ahmad, was likely killed also, the military said.

Colonel Romeo Brawner, deputy task force commander in Marawi, said offensives had stopped, but troops would secure the city from militant "stragglers" who might still be alive.

President Rodrigo Duterte had declared Marawi City liberated six days ago, even though battles were still ongoing. Padilla said that since that declaration, the army had been fighting an enemy decimated by the loss of its leadership.

"They were formless, they had no place to run," he said.

Lorenzana said six battalions of troops would remain in Marawi and though the battle had been won, ISIS' radical ideology had not been completely annihilated.

He thanked the United States, Australia, Singapore and China for providing technical support and weaponry, and said the conflict would be a catalyst for closer international cooperation against extremism.