Philippines President Rodrigo Duterte has warned the nation of the lingering threat of terror attacks as the country's armed forces announced the end of the five-month siege of Marawi City, which was captured by Islamists.

In May 2017, Duterte implemented martial law in the Mindanao region after the Islamist Maute group launched an attack. Since then, the region has been gripped by conflict leaving more than 1,000 people dead and hundreds of thousands displaced.

The Filipino military has been fighting the home-grown Maute militant group, and a faction of Abu Sayyaf, which has pledged allegiance to the Isis.

"In the coming days, with the siege that... I'm not trying to scare you. Let us just be prepared for any eventuality," Duterte told a gathering in Bacolod City on Monday, 23 October.

Though he praised the efforts of Filipino troops in curbing the influence of Islamist groups, he said there is a possibility the extremists would launch attacks.

"No nation has escaped from the clutches of the evil of the ISIS. It's an ideology that is dedicated to just kill human beings and destroy the places whatever, or what kind, heritage and all," said Duterte.

He asked the public to remain vigilant and watch their surroundings in order to avoid a situation like that of Marawi, which witnessed a lengthy conflict.

"Just what happened in Marawi, it was an awful thing to just see what was evolving before our eyes. Kaya mag-preparar kamo sa [So be prepared, exercise] a little bit of caution and everything and it would help if everybody also could watch everybody, not really a profiling. I hate it, I do not do it," said Duterte.

Duterte's comments came shortly after the country's defence secretary formally announced the end of the siege in Marawi.

Defense Secretary Delfin Lorenzana told reporters on Monday that combat operations in Marawi were ending after troops recovered 42 bodies of the last group of militants. "Those are the last group of stragglers of Mautes and they were caught in one building so there was a firefight, so they were finished," he said. "There are no more militants inside Marawi City."

The siege of Marawi

Hundreds of militants, many waving Islamic State group-style black flags, launched the siege on May 23 in Marawi, a bastion of Islamic faith in the south of the largely Roman Catholic Philippines, by seizing the lakeside city's central business district and outlying communities. They ransacked banks and shops, including gun stores, looted houses and smashed statues in a Roman Catholic cathedral, according to the military.

The fighting has left at least 1,131 people dead, including 919 militants and 165 soldiers and police. 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, Army Col. Romeo Brawner said at a news conference Sunday. That left the gunmen with none of the hostages they had used as human shields to slow the military advance for months.

The disastrous uprising, which has displaced hundreds of thousands of Marawi residents, erupted as the Philippines was hosting annual summit meetings of the Association of Southeast Asian Nations this year, along with the 10-nation bloc's Asian and Western counterparts, including the United States and Australia. The two governments have deployed surveillance aircraft and drones to help Filipino troops rout the Marawi militants.

Last week, troops killed the final two surviving leaders of the siege, including Isnilon Hapilon, who is listed among the FBI's most-wanted terror suspects in the world, and Omarkhayam Maute. Following their deaths, President Rodrigo Duterte traveled near the main scene of battle and declared Marawi had been essentially liberated.

DNA tests done in the United States requested by the Philippine military have confirmed the death of Hapilon, according to the U.S. Embassy in Manila. Washington has offered a bounty of up to $5 million for Hapilon, who had been blamed for kidnappings for ransom of American nationals and other terrorist attacks.

Among the foreign militants believed to be with the remaining gunmen in Marawi were Malaysian militant Amin Baco and an Indonesian known only as Qayyim. Both have plotted attacks and provided combat training to local militants for years but have eluded capture in the south.