Pro-Islamic state militants who held school students hostage in the Philippines have been driven into retreat after a fierce gun battle with troops.

Civilians were used as human shields in Pigcawayan town in North Cotabato province on Mindanao island, where a bloody battle between government troops and Islamists has reached its fifth week.

But Brigadier General Restituto Padilla said the jihadists had withdrawn, and the military was investigating whether any civilians were still being held captive.

It comes after earlier reports from police that several students had been trapped by up to three hundreds Bangsamoro Islamic Freedom Fighters (BIFF) miltants.

Scroll down for video

Islamist militants have stormed a school in the southern Philippines and are holding several students hostage, police said. Above, Philippine Marines along a highway in Marawi

'It's already resolved,' Padilla told a regular briefing. 'They've withdrawn, they are no longer there. The school area is again safe. The troops are in pursuit mode.'

Witnesses about a kilometre from the school said they could hear gunfire, with troops preventing anyone from getting closer.

Police said about 300 armed men, among them members of the Bangsamoro Islamic Freedom Fighters (BIFF), stormed the school early on Wednesday.

Abu Misry Mama, a spokesman for the BIFF, said that the militants had taken civilians to a place safe from the crossfire, and did not intend to hold them hostage.

Asked if they would be freed, Mama said: 'Yes. We're not kidnappers.'

Padilla said the incident at Pigcawayan was not related to the fighting in Marawi. 'This has come from a group that has long committed harassments,' he said.

Debris and smoke is seen after an airstrike as government forces continue their assault against insurgents from the Maute group, who have taken over large parts of Marawi City

Earlier, Chief Inspector Realan Mamon, the police chief at Pigcawayan, said in a radio interview civilians were trapped in the crossfire.

'We can confirm that they occupied a school and there were civilians trapped. We are in the process of determining how many were trapped and their identities,' Mamon said.

Mamon added the attack may be an attempt to divert the military's focus away from the militants who have laid siege on southern Marawi city.

He said an unspecified number of BIFF gunmen raided the village of Malagakit in North Cotabato province at dawn Wednesday and engaged government forces in a firefight. Villagers have fled to safety.

Military spokesman Brig. Gen. Restituto Padilla says the gunmen targeted a patrol base of pro-government militiamen and the attack maybe an effort by the militants to divert troop focus on the Marawi offensive.

Pigcawayan is 190 km (120 miles) south of Marawi City, where BIFF militants, along with fighters from other groups allied to ISIS, have been holed up and fighting the Philippines military since May 23.

Philippine President Rodrigo Roa Duterte (right) visiting wounded soldiers confined at Camp Edilberto Evangelista Station Hospital in Cagayan de Oro City on Tuesday

Eliseo Garcesa, mayor of Pigcawayan town, told Philippine radio he was still seeking information about possible casualties.

Philippine aircraft and troops launched a renewed push against the militants in Marawi City on Tuesday.

A military spokesman said the aim was to clear the area by the weekend's Eid festival, although there was no deadline.

The offensive came amid worry that rebel reinforcements could arrive in the city after Eid al-Fitr, which marks the end of the Muslim holy month of Ramadan.

A rescued resident is seen with government forces after he was rescued from his home in Marawi city

A rescued resident points to the picture of one of the insurgent Maute group, who have taken over large parts of Marawi city

Nearly 350 people have been killed, according to an official count, after fighting in Marawi City entered a fifth week.

As of Tuesday, the military said 258 militants, 65 security personnel and 26 civilians had been killed. Hundreds of people are unaccounted for, with many believed to be hiding in the basements of the city.

Fleeing residents said they have seen scores of bodies in the debris of homes destroyed in bombing and cross-fire.

The seizure of Marawi and the dogged fight to regain control of it has alarmed Southeast Asian nations which fear ISIS - on a backfoot in Iraq and Syria - is trying to set up a stronghold in the Muslim south of the mainly Roman Catholic Philippines in a move that could threaten the whole region.

President Rodrigo Duterte visited a school where people who fled from Marawi are being housed and apologised for their plight, especially since it was Ramadan.

And during a visit to see wounded soldiers at Camp Evangelista Station Hospital in Cagayan de Oro City, Duterte warned that a civil war could erupt in Mindanao if Christians took up arms against Islamist fighters.