The Afghan government said the prison siege in Kabul ended on Wednesday after all 1300 prisoners involved in a riot that broke out at the weekend moved to a new block under police control.
Mohammad Qasim Hashimzai, the deputy justice minister, told reporters: "All the prisoners, including the political ones have been moved to another block."
"The agitation is over. The police are now in full control of the prison."
As many as five people died in the unrest led by Taliban prisoners at Pul-i-Charkhi jail on Kabul's outskirts that erupted after prisoners were issued uniforms to prevent a repeat of a January escape by seven Taliban who mingled with visitors.
A prisoner said that their demands included improved living conditions and a review of their cases, but he did not know what the alleged al-Qaida and Taliban detainees wanted.
Trouble began when inmates attacked wardens with makeshift weapons, breaking windows and doors and setting alight bedding and furniture.
The authorities blame the riots
on al-Qaida and Taliban prisoners
Walls separating units for criminals, political prisoners and women were smashed through and police had periodically fired into the building to try to control the prisoners, officials said.
Troops and security forces surrounded the block for two days and on Monday the army threatened to storm the building if talks failed.
Negotiators had accepted some of the demands, officials said.
The prisoners then released the women prisoners, many of whom had children with them, and two female guards after the talks on Monday.
They also agreed for the dead and wounded to be removed from the block.
Police on Tuesday blamed the rioting on a core of 100 al-Qaida and Taliban prisoners in the block's political wing, which held about 300 men.
"What is clear at this stage (is that) some Taliban and al-Qaida prisoners wanted to create chaos and escape," police rapid reaction force commander General Mahboob Amiri told AFP.
Most al-Qaida suspects caught in Afghanistan after the US-led invasion to topple the Taliban regime in late 2001 have been transferred to Guantanamo Bay or the US jail at Bagram Air Base in Afghanistan.
But a number of lower-ranking, foreign al-Qaida militants and some Afghans said to have close ties to the network are still housed in Pul-e-Charkhi, along with rank-and-file Taliban fighters, officials say.
The rundown jail was notorious for the detention and torture of thousands of people during communist rule in the 1980s.