Metro Manila (CNN Philippines, October 17) — President Rodrigo Duterte on Tuesday declared Marawi is free from "terrorist influence," as military operations continue to ensure all terrorists have been flushed out.

"I hereby declare Marawi City liberated from the terrorist influence that marks the beginning of rehabilitation of Marawi," the President said in a visit to Marawi.

The military clarified the war is not over yet, but it will only take "a matter of days."

"(The) declaration of the liberation of Marawi is a strategic statement, meaning it's a message that we want to tell the world, that tapos na po itong problema ng Maute-ISIS (that the Maute-ISIS problem is over). They cannot be victorious anymore. Wala na po, patapos na po (It's about to be over)," said Col. Romeo Brawner, Deputy Commander of Joint Task Force Ranao.

He said the death of terrorist leaders Omar Maute and Isnilon Hapilon on Monday led to Marawi's liberation. The two were killed in the main battle zone of Marawi, the provincial capital of Lanao del Sur, over 1,400 kilometers south of Manila.

Also read: 'Terrorists will crumble': Military kills Isnilon Hapilon, Omar Maute

In a statement, Presidential Spokesperson Ernesto Abella said the President's announcement marks the beginning of Marawi's rehabilitation.

"Our ground commanders will determine if it is safe for residents to return to the city as there may still be traps and unexploded ordnance in some areas. We will defer to their assessment and await their recommendation," he said.

Tying loose ends

The military is still after Dr. Mahmud Ahmad, a Malaysian terrorist who joined the ISIS-inspired Maute group and supposedly funded the Marawi attack.

"He's not as strong as the other two leaders...We hope to be able to get him very soon," Brawner said.

A total of 847 terrorists, 163 government troops, and 47 civilians were killed in Marawi since May 23, when the battle between troops and terrorists began, prompting Duterte to declare martial law in Mindanao.

Brawner called for the understanding of over 300,000 displaced residents, saying they cannot return to their homes yet until the military finishes clearing Marawi of terrorists and explosives.

Shortly before noon on Tuesday, Armed Forces spokesperson Major General Restituto Padilla said some 20 Maute terrorists are still holding over 20 hostages.

Timeline of the terror crisis

It took the government nearly five months to defeat the Maute group, killing over 800 of the enemies which the military said included foreign terrorists.

Maute hostages were forced to fight government troops.

Abducted Catholic priest Chito Soganub in a May 30 video said captives included church workers, a professor of the Mindanao State University, teachers from the Dansalan College Foundation Inc., carpenters, household helpers, children, Christian settlers, and tribe members.

Suganob was rescued on September 16, near Bato Mosque, one of the main strongholds of the Maute terrorists.

As early as June 29, Duterte said the rebellion might end in just a matter of days. But as the weeks dragged on, it became clear that government troops were facing an enemy that had long prepared for the battle. Some P79 million in cash and checks, as well as illegal drugs and drug paraphernalia left behind by Maute, and tunnels underneath the city were discovered by troops who did painstaking house-to-house searches for the enemy amid booby traps.

But on September 1, 102nd day of the Marawi crisis, Armed Forces spokesman Brigadier General Restituto Padilla said military operations have entered the "final push," and fighting was expected to intensify.

Martial law in Mindanao was supposed to lapse last July 22 in line with the 60-day limit under the Constitution, but Congress granted Duterte's request for an extension until end of this year "to quell the rebellion."

Duterte in September revealed he considered lifting martial law in Mindanao but a possible spillover of the terror crisis held him back.

He visited Marawi six times to boost the soldiers' morale. He declared the liberation of Marawi during his seventh visit.

The government now faces the challenge of rebuilding Marawi. The heavy fighting and airstrikes left buildings in ruins, homes reduced to rubble.

It will cost more than ₱50 billion to rehabilitate the war-torn city, Duterte and Defense Secretary Delfin Lorenzana said.

Read: Gov't needs more than ₱50 billion to rebuild Marawi

CNN Philippines' Gerg Cahiles contributed to this report.