The attack happened yesterday in Plateau state, which has been dogged for years by ethnic, sectarian and religious unrest.
Sunday Audu, the head of the Irigwe Community Development Association, said armed men stormed the school in the village of Nkyie Doghwro, in the Bassa area of the state.
Hundreds of local residents had sought refuge there for fear of reprisal attacks, after unidentified assailants killed six cattle herders on Sunday.
Plateau police spokesman Tyopev Terna confirmed the attack but declined to give a death toll.
More From This Section
Audu blamed the killings on the mostly nomadic Fulani herdsmen, accusing them of being "in denial of sponsoring these attacks".
But the head of the Miyetti Allah Cattle Breeders Association of Nigeria (MACBAN) in Bassa, Umaru Sangare, denied claims they were to blame.
"We have no hand in the attack against the Irigwe, despite the fact that our six men were killed on Sunday and beheaded at Bajju village while grazing," he said.
Plateau state lies on the dividing line between Nigeria's mainly Christian south and the mostly Muslim north. It has seen sporadic violence and tensions for decades.
The violence has been attributed to a battle for resources because of drought and desertification in northern Nigeria and the wider Sahel region, forcing herders further south.
Farming communities, most of which are Christian, have complained the herdsmen, who are mainly Muslim, damage their fields and crops with their livestock.
Fulani leaders say they are deprived of basic rights, such as access to land, education and even political office.
Tensions frequently boil over and more than 10,000 people have been killed in the state since the turn of the century, according to groups tracking the violence.
Last month, the International Crisis Group (ICG) warned in a report that the clashes threatened Nigeria's national security and were becoming as dangerous as Boko Haram Islamists.