Suspected Islamist militants from Boko Haram have attacked an army barracks in the Nigerian city of Maiduguri.
The army said it had repelled the attack, inflicting heavy casualties. Eyewitnesses said there were deaths on both sides.
The assault on the barracks was an attempt by the attackers to free colleagues held there, a military spokesman said.
Militants suspected to be from Boko Haram have killed 500 people this year.
‘Hiding in mango tree’
Residents said there was a heavy exchange of fire and explosions near Giwa barracks, as the military battled the insurgents.
A military source told the AFP news agency that dozens of suspected militants had been freed – a report which defence ministry spokesman Chris Olukolade neither confirmed nor denied.
In a statement, the military said it believed the insurgents were trying “to boost their depleted stock of fighters” by freeing fellow militants.
“They set many houses on fire and killed innocent people,” local resident Jamila Yusuf told Nigeria’s Daily Trust newspaper.
The air force was deployed and some suspected Boko Haram fighters were killed as they fled across a dry river bed behind the barracks, residents said.
One woman, who for safety reasons did not want to be named, told the BBC she had seen a pile of 15 corpses near the barracks.
She said soldiers then found a suspected militant hiding in a mango tree.
“They pulled him out, shot him and put him on the heap of corpses,” the witness told the BBC’s Focus on Africa radio programme.
The woman also she saw a group of vigilantes parading around the streets with the severed leg and hand of a suspected militant.
She said Maiduguri residents were constantly worried about attacks and so were happy to capture and kill Boko Haram members.
Maj-Gen Olukolade said the attackers had suffered “heavy casualties” in their attempt to free detainees. He said four soldiers had been wounded.
Human rights groups say hundreds of suspects held in Giwa barracks have died and torture there has been rife. The army has always denied mistreating suspects.
Eyewitnesses in Maiduguri have seen dead bodies of what appear to be both insurgents and Nigerian soldiers after the attack.
Many civilians were also reportedly killed.
It came as UN Human Rights Commissioner Navi Pillay was in the country. She told journalists that “many Nigerians openly acknowledge human rights violations have been committed by the security forces”.
“These have served to alienate communities, and create fertile ground for Boko Haram to cultivate new recruits,” she said.
There was also at least one explosion at Maiduguri university and houses were hit, residents say. It is not clear whether the blasts were set off by Boko Haram or whether they were the result of strikes by the air force.
BBC Nigeria correspondent Will Ross says Boko Haram militants usually attack at night so this was a particularly brazen assault.
Attacks have intensified in recent weeks despite a state of emergency being declared in north-eastern Nigeria last year.
Human Rights Watch says in a report that the attacks by Boko Haram are having a devastating impact on the population of north-eastern Nigeria.
Quoting United Nations figures, it says some 300,000 people have fled their homes over the past year.
“Even if the government can’t stop the attacks, at the very least, it can meaningfully assist the people who have been most devastated by them,” says HRW’s Africa director Daniel Bekele.
Boko Haram was founded in Maiduguri in 2009. It wants northern Nigeria to become an Islamic state.