Philippine President Rodrigo Duterte declared the southern city of Marawi liberated from pro-Islamic State militants on Tuesday, although the military said 20-30 rebels were holding about 20 hostages and still fighting it out.

In a rousing address to soldiers a day after the killing of two commanders of the rebel alliance, Duterte said he would never again allow militants to stockpile so many weapons, but Marawi was now free and it was time to heal wounds and rebuild.

"I hereby declare Marawi City liberated from terrorist influence, that marks the beginning of rehabilitation," Duterte, wearing a camouflage cap and dark sunglasses, said during his unannounced visit.