Gunmen have attacked the main prison in Niger's capital, Niamey, killing at least two guards, officials say.
They are thought to be members of the Islamist militant group, Movement for Unity and Jihad in West Africa (Mujao).
Officials said several inmates were overpowered and detained after what appeared to be an attempted breakout.
The attack comes days after Mujao said it was behind suicide bombings at a military base and a French-operated uranium mine which killed 25 people.
Another group affiliated with al-Qaeda, the Signed-in-Blood Battalion of Algerian militant Mokhtar Belmokhtar, later claimed that the assaults in Agadez and Arlit had been joint operations with Mujao.
It also said the attacks were retaliation for Niger's role in the French-led military offensive which drove Mujao and two other Islamist groups out of northern Mali earlier this year.
'Wanted for terrorism'
Residents said the gunmen launched the attack on the prison in Niamey at around 15:00 local time on Saturday.
"We were sitting there when we saw these armed men start to shoot at the guards... I saw several of them fall and not get back up," Ila Yaye, who lives near the prison, told the Reuters news agency.
Officials told the BBC the incident started when a prisoner grabbed a gun from a guard, and shot dead three guards and a civilian. The prisoner was believed to be a Sudanese member of Mujao.
Members of the group stationed outside the prison then opened fire, the officials said. Some were reported to have entered the building.
Nigerien gendarmes are reported to have later arrived at the prison to help the guards, who remained under fire for around 45 minutes. Police meanwhile blocked off roads leading to the facility.
Later, Niger's Justice Minister, Marou Amadou, said only two guards had been killed and another seriously wounded by four inmates.
Mr Amadou said the inmates had been captured and the incident was being investigated.
"There are two versions of what happened, and right now we think it's more likely that they came from inside the jail," he said.
"These are people who are wanted for terrorism. We do not know how they were able to arm themselves inside the prison, and how they were able to get out to attack the guards."
Mr Amadou said it was too early to say which group was behind it.
Mujao is a splinter group of al-Qaeda in the Islamic Maghreb (AQIM), which formally announced its existence following the abduction of three aid workers in Algeria in October 2011.
It says its objective is to spread jihad to West Africa rather than confine itself to the Sahel and Maghreb regions - the main focus of AQIM.