MARAWI CITY/CLARK, Philippines (Reuters) - The Philippines on Monday announced the end of five months of military operations in a southern city held by pro-Islamic State 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 put a stop to the last stand of rebel gunmen who clung on inside several buildings in the heart of Marawi, and refused to surrender. Artillery and automatic gunfire were still heard on Monday and Reuters journalists saw flames behind a mosque. The bodies of 40 fighters and two of their wives were found there and in two buildings close by.  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 in Clark at a meeting of regional defense ministers. 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 organization 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. 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. The deputy task force commander in Marawi, Colonel Romeo Brawner, said troops would secure the city from militant  stragglers  who might still be alive.  If we find them and they will attack our soldiers or even the civilians, then we will have to defend ourselves,  he told reporters.    After months of slow progress, the military has made significant gains in retaking Marawi in the week since Isnilon Hapilon, Islamic State s  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. Military spokesman, Major General Restituto Padilla, confirmed there was still gunfire ongoing, but there were  no more terrorists  and the army s last battles were with an enemy decimated by the loss of its leadership.  They were formless, they had no place to run,  he said.      Duterte had declared Marawi City 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 .  I m not trying to scare you, but let s just be prepared for any event,  he said. Lorenzana said six battalions of troops would remain in Marawi and though the battle had been won, the enemy s radical ideology had not been completely annihilated.  He thanked the United States, Australia, Singapore and China for providing weaponry and technical support, including surveillance aircraft, and said the conflict would be a catalyst for closer international cooperation against extremism. The government estimates the rebuilding of the heart of Marawi could cost in excess of $1 billion.  