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.