FIBB fighters abandon positions after taking over a primary school in Mindanao and using civilians human shields.

Rebel fighters who stormed a southern Philippines village and occupied a school on the southern island of Mindanao are on the run after freeing dozens of hostages following a day-long crisis, according to the military.

The gunmen escaped from the public elementary school in the village of Malagakit, close to Pigcawayan town, as darkness fell, Captain Arvin Encinas, an army spokesman, told dpa news agency.

“They escaped as troops slowly moved in,” he said.

Six hostages were still unaccounted for, said Captain Nap Alcarioto, another spokesman.

Philippine troops killed at least four of the fighters, who belong to an armed group that has pledged allegiance to the Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group.

Two government soldiers were wounded in the fighting, which forced nearly 1,000 residents to flee their homes in Malagakit and two other villages in Pigcawayan in North Cotabato province, nearly 900km from the capital, Manila.

The armed men, numbering around 200, had planned to attack an army base in the nearby village of Simsiman, but were pushed back by government troops who blocked their advance until reinforcements arrived, Alcarioto said.

The fighters then occupied the school and seized nearly 40 civilians, including 12 minors, as human shields.

They also laid out explosives around the school to stop the soldiers, he added.

Thirty-one hostages, including 12 minors, were freed by the gunmen or were able to escape from the school before the fighters withdrew.

The gunmen were members of the Bangsamoro Islamic Freedom Fighters (BIFF), a breakaway faction of a larger Muslim separatist rebel group that signed a peace agreement with the Philippine government in 2014.

The group claimed responsibility for the attack, saying it was in retaliation for a series of military offensives in North Cotabato and nearby Maguindanao province.

The BIFF has been blamed in the past for bombings and kidnappings in the central part of the southern region of Mindanao.

President Rodrigo Duterte last month declared a state of emergency on the southern island after ISIL-linked fighters laid siege on Marawi City, some 190km north Pigcawayan.

The conflict in Marawi City began on May 23 when hundreds of fighters went on a rampage after government forces tried to arrest a local armed group leader.

“Although the situation in Pigcawayan may not be directly linked to the fighting that has been raging in Marawi for the past few weeks, it may have something to do with the martial law that been imposed across the region,” Al Jazeera’s Jamela Alindogan, reporting from Mindanao, said.

More than 380 people have been killed in the crisis, including 268 fighters and 66 government forces. The gunmen have also killed 26 civilians, while 24 people died from illnesses in evacuation centres.

The fighting has displaced more than 300,000 residents and left Marawi City in ruins, with houses and buildings torched by militants or destroyed by bombs from military air attacks.