Up to six guards were killed, one police source said, before security forces began firing into the unarmed prisoners.
There was confusion over casualty figures.
Another police source and an Interior Ministry official initially said more than 20 prisoners were killed, but a second official insisted there were 15 casualties in all, with some only wounded, and that these included one dead guard and one wounded officer.
Later, a source at Baghdad police headquarters said it was still unclear just how many people were killed, but that the first prisoner to seize a rifle had shot and killed six guards.
The various accounts converged in saying that the trouble began when the prisoner grabbed a weapon from one of the guards and shot him.
One Interior Ministry official said the guard was wounded while a second prisoner also took a machingun from another guard and shot him dead.
Prisoners have been found abused
A police source said the prisoners, being held at the Adala Iraqi army base – known to US forces as Camp Justice – in the northern Shia district of al-Kadhimiya, were on a morning recreation break when the incident began.
The first detainee to open fire managed to kill six armed guards before being shot and killed.
It was not clear how he had been able to kill so many.
At least three prisoners were unaccounted for and may have escaped, the police source said.
Doctors at a nearby hospital said they had received five bodies from the camp on Wednesday morning.
Prison conditions in Iraq have been a matter of controversy.
US officials have expressed disquiet since the discovery by US troops last month of dozens of abused Sunni Arab suspects in a secret bunker run by the Interior Ministry, which minority Sunnis accuse Shia sectarian militias of running .
The US military is holding about 14,000 Iraqis and say they will not transfer them to Iraqi custody until they are sure of better standards.
US troops were found to have abused prisoners in 2003 at Baghdad’s notorious Abu Ghraib prison. In other incidents, US troops have shot dead unarmed detainees during prison riots.
An armed group in Iraq meanwhile released a video of a French engineer kidnapped three weeks ago and denounced the “illegal French presence” in the country.
Many foreigners have been
The video, an excerpt of which was aired on the Arab news channel Al-Arabiya, showed the hostage, identified as Bernard Planche, sitting on a chair with two armed men on either side of him.
“I am sorry for everything that has happened … I want to thank all those who are trying to help me,” Planche said.
He identified himself as “Bernard” and said he worked on water projects in Baghdad.
The name of a previous unknown armed group, called “Monitoring For Iraq,” was shown in the corner of the footage.
Al-Arabiya said the group on the tape said they opposed the “illegal French presence” in Iraq and demanded the withdrawal of French troops from the country.
France has not sent forces to Iraq.
Planche, an engineer working for a non-governmental organisation called AACCESS, was kidnapped on 5 December on his way to work at a water plant in downtown Baghdad.