The military, boosted by the deaths of two key militant leaders in a gunbattle the day before, hopes the current fighting is the final phase of defeating a dwindling band of fighters who are now trapped in an area the army says is about 2 hectares (5 acres).
Duterte visited the battle-scarred city on Tuesday where to cheers from rain-drenched troops he announced its liberation in a short speech from a stage at a ruined school campus about a kilometer from the fighting.
"Ladies and gentlemen, I hereby declare Marawi city liberated from the terrorist influence," he said.
To the side of stage of the stage, a large banner displayed photos of the slain militant leaders.
Military chief Gen. Eduardo Ano told The Associated Press that Duterte's statement means the threat from the militants, who've occupied parts of the lakeside city for five months, is substantially over.
"They're leaderless and they have no more organization," he said. "There are still skirmishes."
According to military spokesman Restituto Padilla, there are 20 to 30 militants left in Marawi, including six to eight foreign fighters. They have about 20 hostages, including women and children, he said. As many as 80 buildings will need to be swept for explosives.
Marawi, a mosque-studded center of Islamic faith in the predominantly Roman Catholic Philippines, has been devastated by the siege laid by the Daesh terrorist group-allied militants who overran the city on May 23. More than 1,000 people have been killed, including about 800 militants.
The surprise occupation of the city and the involvement of foreign fighters set off alarms in Southeast Asia and the West. Analysts said parts of the southern Philippines were at risk of becoming a new base for Daesh as it lost territory to international forces in Iraq and Syria.
Philippine flags hung on Tuesday from pockmarked buildings and houses in Marawi, their roofs either blasted away or riddled with gunshot holes.
Soldiers stood guard in front of some buildings and at intersections where battle debris has been shoveled to the side.
The Philippine government on Monday confirmed an Associated Press report that two key figures behind the siege, Isnilon Hapilon, who is listed among the FBI's most-wanted terror suspects, and Omarkhayam Maute, were killed in a gunbattle.
A top Malaysian militant, Mahmud bin Ahmad, who uses the nom de guerre Abu Handzalah and is a close associate of Hapilon, has not been found and was among the remaining militants being hunted by troops.
At a public hall converted into an evacuation center just outside Marawi, there was joy among evacuees at news of the two men's deaths and hopes of a return to some form of normality.
Evacuees chatted about the news and looked at Facebook posts showing pictures of the dead Hapilon and Maute.
"We're very happy because they have lost their leaders. I hope that all of them will be wiped out," said Seima Munting, a 40-year-old mother of four who is among 750 people living at the hall in Balo-i township.
"My brother told me that finally we can return home, but when? When can we finally return home? What will we return to? Do we still have a house? Do we have jobs?" she said.