"I hereby declare Marawi City liberated from the terrorist influence that marks the beginning of rehabilitation of Marawi," Duterte said while visiting the city, on the southern Philippines island of Mindanao.
Around 20 to 30 militants remain in the city, holding about 20 hostages, Maj. Gen. Restituto Padilla, spokesman for the Armed Forces of the Philippines (AFP), said at a press conference earlier in Manila.
Fighting continues in Marawi, despite Duterte's declaration of liberation.
General Eduardo Ano, Chief of Staff for the AFP, told reporters in Marawi that since such a small number of militants remain in a small area of the city, it can be considered a law enforcement matter and mopping-up operations against those militants are now underway.
A military commander in the region said the declaration was "a strategic statement."
"It's a message that we want to tell the world, that the Maute-ISIS problem is over. They cannot be victorious anymore. It's about to be over," said Col. Romeo Brawner, Deputy Commander of the Joint Task Group Ranao, told CNN affiliate CNN Philippines
Bloody, protracted conflict
Parts of the Muslim-majority city had been under the control of the Islamist Maute group since a shock invasion by militants at the end of May.
In the 150 days since the Philippines army launched an operation to flush them out, more than 800 militants and 162 government security forces had been killed, said Gen. Ano said.
In that time, around 1,700 hostages were rescued, including 20 on Monday, he added.
The violence forced more than 350,000 residents to flee the city and the surrounding areas, as their homes were reduced to rubble by airstrikes and militant fire.
Images from the city show rows of burned houses, pocked with bullet holes were ISIS fighters attempted to hold back advancing troops.
Residents have been told they can't return home until the military finishes clearing the city of terrorists and explosives.
It will cost more than $1 billion to rebuild the city, officials say, according to CNN Philippines.
Key leaders killed
The announcement of the city's liberation comes one day after the country's Defense Secretary, Delfin Lorenzana, said two
leading militants -- Ipsilon Hapilon and Omar Maute -- were killed in a firefight.
Hapilon was the leader of the Abu Sayyaf terror group, and was named by ISIS as the group's emir in Southeast Asia. Omar Maute was one of the two leaders of the Maute group, along with his brother Abdullah, the main militant force behind the siege.
Abdullah Maute is suspected to have been killed in an attack in September, though no definitive proof of his demise has been found. Omar's death had been reported multiple times in the past, though never confirmed.
Hapilon and Maute were killed, along with seven other militants, while attempting to exit a building at street level during a four-hour firefight, Ano said at a news conference. Maute was shot in the head by a sniper.
Their bodies were positively identified by a former hostage, the spokesman said.
"The Maute brothers were essentially the military brain and engine of the whole ISIS-affiliated movement in the Philippines," said Richard Heydarian, a security analyst and author of the new book, "The Rise of Duterte: A Populist Revolt against Elite Democracy."
How the fighting started
The retaking of Marawi is a "big setback" for ISIS' ambitions in the region, Scott Stewart, Vice President of Tactical Analysis of American geopolitical intelligence firm Stratfor, told CNN.
"The loss of so many key leaders is important, especially those with international ties, (who) can command funding and manpower ... is a big setback for IS, and especially for (Hapilon's) IS-Abu Sayyaf Basilan militant group, but there is a lot of work there to do to make sure they don't regroup and come back stronger," he said, using an alternate acronym for ISIS.
"It's not the total endgame. They can regroup. (Militant group) BIFF (Bangsamoro Islamic Freedom Fighters) is still running around Mindanao. Between them and other Islamist militants, militancy (in the region) isn't going to end any time soon," he says.
"We're not out of the woods yet."