DAMATURU, Nigeria -- Islamic militants set fire to a locked dormitory at a school in northern Nigeria, then shot and slit the throats of students who tried to escape through windows during a pre-dawn attack Tuesday. At least 58 students were killed, including many who were burned alive.

They "slaughtered them like sheep" with machetes, and gunned down those who ran away, said one teacher, Adamu Garba.

Soldiers guarding a checkpoint near the coed government school were mysteriously withdrawn hours before it was targeted by the militants, said the spokesman for the governor of northeastern Yobe state.

Female students were spared in the attack, said the spokesman, Abdullahi Bego, though girls and women have been abducted in the past by militants of the Boko Haram movement, whose name means "Western education is forbidden."

This time, the insurgents went to the female dormitories and told the young women to go home, get married and abandon the Western education they said is anathema to Islam, Bego said. All of the dead were teenage boys or young men.

The militants, whose struggle for an Islamic state has killed thousands and made them the biggest threat to security in Africa's top oil producer, have increasingly preyed on civilians, both Muslim and Christian. Some 300 people have died in attacks this month alone.

Local officials buried the bodies of 29 victims and another 29 were taken to Damaturu Specialist Hospital, according to the hospital records and an Associated Press reporter who went to the mortuary. Most of the victims appeared to be between 15 and 20 years old, Bego said.

Eleven wounded survivors of the attack were being treated at the hospital.

Touring the smouldering ruins Tuesday at the Federal Government College of Buni Yadi, Gov. Ibrahim Gaidam decried the federal government's failure to protect the population.

"It is unfortunate that our children in schools are dying from lack of adequate protection from the federal government," Gaidam told reporters.

He called on President Goodluck Jonathan to deploy more troops to the region.

Jonathan, who rarely comments on individual attacks, said in a statement that he felt "immense sadness and anguish" by the loss of life at the school, and vowed that the military would "continue to prosecute the war against terror with full vigour, diligence and determination."

Garba said the militants locked the door of a dormitory where male students were sleeping, then set it on fire. Some students were burned alive in the attack that began around 2 a.m., he said.

The governor said it took hours for troops to arrive, giving the assailants plenty of time to set the rest of the school campus ablaze-- six dormitories, the administrative building, staff quarters, classrooms, a clinic and the kitchen.

Bego, the governor's spokesman, said the governor will be looking into why the school was left unprotected. "The community complained to the governor that yesterday the military were withdrawn and then the attack happened," he said.

Soldiers from Damaturu, the state capital located some 70 kilometres away, did not arrive until noon, hours after the attackers had taken off, according to community leaders.

Military spokesman Eli Lazarus confirmed the attack, but could not give an exact death toll because soldiers were still gathering corpses. He had no immediate comment on the charge that soldiers withdrew before the attack.

Nigeria's military has reported arresting several soldiers accused of aiding and passing information to Boko Haram extremists; a senator has also been accused of similar charges.

On Monday, Jonathan dismissed suggestions the military was losing the war to halt the 4-year-old Islamic uprising in the northeast.

Tens of thousands of Nigerians have lost family members, houses, businesses, their belongings and livelihoods to the rebellion and the fallout from a military state of emergency by soldiers accused of gross human rights violations, including setting ablaze entire villages and summary executions of suspects.

Tuesday's attack is only the latest in a string of deadly assaults by Islamic militants.

Entire towns and villages were under the sway of Boko Haram when Jonathan declared a state of emergency in May. The military quickly forced the insurgents out of urban areas, only to have them regroup in forests and mountain caves where it has proved difficult to flush them out.

The military said recent attacks are being perpetrated by militants escaping a sustained aerial bombardment and ground assaults on their forest hideouts along the border with Cameroon, an offensive begun after Jonathan fired and replaced his entire military command last month. On Saturday, the military announced it had closed hundreds of miles of the border with Cameroon to prevent militants using it as a launch pad for attacks.

U.S. Secretary of State John Kerry on Monday condemned the "unspeakable violence and acts of terror" and said the United States was helping Nigerian authorities "to combat the threat posed by Boko Haram, while protecting civilians and ensuring respect for human rights."

But survivors and local officials charge they get no protection.

"Everybody is living in fear," local government chairman Maina Ularamu told the AP after Izghe village was attacked twice in a week this month -- with militants killing 109 people and burning hundreds of thatched huts in neighbouring Adamawa state.

"There is no protection. We cannot predict where and when they are going to attack. People can't sleep with their eyes closed," Ularamu said.