Some 25 people, mostly students, have been killed by unknown gunmen in Mubi, north-eastern Nigeria, police say.
Twenty-two of the dead were students whom attackers had called out by name, a police spokesman told the BBC.
A local resident said at least 40 people had been shot dead or stabbed.
The killings come days after a major operation against the Boko Haram militant group in the town, while others have linked them to a dispute over student union elections.
Rivalries over student elections have turned violent before but have never reached this level, says the BBC’s Nigeria correspondent Will Ross.
Mobile phone masts in the area were recently attacked by Boko Haram militants, so getting information from Mubi is difficult, adds our correspondent.
‘Everybody is scared’
Investigations were under way, said Adamawa state police spokesman Mohammed Ibrahim, who had just visited the scene, adding that the motive for the attack was not yet clear.
But he said the attackers had inside knowledge: “The attackers called the victims by name and killed them.”
Two of the dead were security guards and the other an elderly resident, said Mr Ibrahim.
One resident who did not want his name to be used, told the BBC’s Hausa service that men in military uniform went to a hall of residence away from the Federal Polytechnic Mubi campus just before midnight, got the students out of their rooms and ordered them to say their names.
Some were then shot dead and others stabbed with knives, and their bodies left in lines outside the buildings.
He said it was not clear why some were killed and others spared – some of the dead were Muslim while others were Christian.
“Everybody is scared,” he said, adding that the shooting lasted for about two hours.
He added that students were now leaving the town, many with tree branches over their cars – a traditional sign of neutrality in Nigeria.
The authorities have imposed an indefinite curfew in the town and ordered residents to stay indoors.
The university has been temporarily closed.
Last week, the Nigerian military carried out an operation in Mubi and arrested dozens of people over suspected links to Boko Haram.
Mubi is in Adamawa state, which has a mixed Muslim and Christian population and borders Borno state, where Boko Haram came to prominence in 2009, staging an uprising in the state capital, Maiduguri.
Boko Haram has not yet commented on the Mubi attacks.
It is fighting to establish Islamic law in Nigeria and has killed more than 1,000 people in numerous attacks across northern and central areas this year.