Image copyright AFP Image caption Dozens of residents managed to flee before the ceasefire broke down

Hundreds of civilians remain trapped in the besieged Philippine city of Marawi after gunfire disrupted a four-hour truce to evacuate them.

Officials had hoped that around 1,000 residents would leave the city but only some 130 were freed, reports said.

The ceasefire between the army and militants allied to so-called Islamic State (IS) had been reached through intermediaries.

The fighting has left more 170 dead, including at least 20 civilians.

The ceasefire was expected to last until 12:00 local time (04:00 GMT). But one hour into it, gunfire broke out, apparently preventing residents from leaving the city, Reuters news agency reported.

It was not clear who was firing. A government representative said negotiations were continuing for another temporary ceasefire on Monday.

Most of the civilians have already fled Marawi but up to 2,000 are believed to be in the city.

The truce had been mediated by the Moro Islamic Liberation Front (MILF) rebel group, a separatist movement based on Mindanao island, where Marawi is located. They have signed accords with the government aimed at forging a final peace.

Image copyright AFP Image caption Fighting in the city has left 120 militants and 38 government forces dead, officials say

The violence in Marawi began last month when the army failed in its attempt to capture Isnilon Hapilon, believed to be the main IS leader in the Philippines and linked to the local Maute group, who have declared allegiance to IS.

In response the Maute group attacked parts of the city with a population of 200,000, taking hostages. President Rodrigo Duterte then declared martial law on Mindanao.

The Philippine military, using armed forces and helicopter airstrikes, have retaken many areas, but others remain in rebel hands.

The Philippines, which is majority Catholic, has faced Muslim separatist movements for decades in Mindanao with its significant Muslim population.

Marawi is known as "Islamic City" in the Philippines for its Muslim-majority population.