Philippine President Rodrigo Duterte fired a rifle towards IS-linked militants during a visit on Thursday to the battle zone in southern Marawi, after troops recaptured a main mosque where the gunmen had taken cover with their hostages in the three-month siege of the city, officials said.

Clad in a combat uniform, protective vest and helmet, Duterte congratulated the troops for regaining control of the Islamic Centre, an indication they are entering the final stage in ending the disastrous uprising. It was Duterte's third known trip to the embattled city.

During his brief visit, Duterte inspected a devastated community near the frontline and talked to troops guarding a recaptured building. He also visited a military patrol base and "tried a sniper rifle and fired twice towards the direction of the terrorists", a government statement said.

Armyinfo-icon Colonel Romeo Brawner said Duterte went to the main battle area, a cluster of dense, mosque-dotted communities which has been heavily damaged in the fighting, with military chief General Eduardo Ano and top commanders.

More than 760 people, including 595 militants, have died in the Marawi fighting, which has sparked concerns that IS may have taken a foothold in Southeast Asiainfo-icon through local extremists as it suffers battle setbacks in Syriainfo-icon and Iraqinfo-icon.

About 600 gunmen launched the insurrection in Marawi's commercial centre on May 23 after a botched army raid to capture the group's leader, Isnilon Hapilon, according to the military.

The United States and Australiainfo-icon have deployed surveillance aircraft to help Filipino troops locate the hundreds of militants who took positions in buildings, mosques and houses, some of them linked by underground tunnels. Chinainfo-icon provided heavy weaponry and Southeast Asian governments offered aid for troops and the hundreds of thousands of displaced residents.

It was not immediately clear if any militants or their hostages were in the mosque when troops entered the building on Thursday after weeks of painstakingly slow advances because of sniper fire and an order from Duterte to avoid any massive attack that might harm an estimated several dozen hostages, including a Roman Catholic priest, used by the gunmen as human shields.

The military says about 40 gunmen are still fighting in the main battle zone, now confined to a smaller cluster of communities after troops backed by air strikes and artillery fire recaptured key bridges and crossed over a river toward the main militant position.