At least nine people, including five guards and police, were killed on Friday at the sprawling Soviet-era Pul-i-Charki prison complex on the outskirts of the capital.
"The two prisoners resisting were killed by Afghan National Army soldiers. The issue is now over," said General Zaher Azimi, spokesman for the Ministry of Defence.
Two other prisoners were killed earlier when a group of prisoners attempted to break out of the jail soon after dawn. Three of the dead prisoners were believed to be Pakistanis and the fourth an Iraqi.
Trooper Zabiullah said outside the prison's main gate how he and two other soldiers had entered the building where the gunmen were hiding in a final assault.
"We went inside, there was three of us. One of us was wounded but the two Pakistanis were killed. The operation is over," Zabiullah said minutes after a burst of small-arms fire inside the prison compound.
An explosion was heard soon after, but police said it was a tank shell fired in jubilation.
Prisoners accused of being
al-Qaida are kept in the prison
Police and militia forces armed with machineguns and rocket-propelled grenade launchers surrounded the building, but authorities finally ordered a rapid reaction force, supported by two tanks, to bring the siege to an end.
Afghan troops deployed around the prison and two armoured vehicles belonging to the German contingent of the Nato-led peacekeeping force stationed in Kabul stood by on the deserted plain outside the prison walls.
Some peacekeepers were seen entering the prison, but a spokesmen for the International Security Assistance Force (ISAF) said none of its troops was involved in the operation.
Abdul Salam Bakhshi, chief of the prison, described how one prisoner had knifed a guard to death and shot two more officers with a rifle taken from the dead man.
Afghan authorities in September freed 368 Pakistanis who were fighting for the Taliban when US and Afghan opposition forces drove the militia from power in the wake of the 11 September 2001 attacks on the United States.
Inmates released from Pul-i-Charki last September said the jail was a vast improvement on the notorious Shiberghan prison in the north, where they had been held by forces loyal to General Abdul Rashid Dostum, an ethnic Uzbek commander.
Dostum's forces are accused of killing hundreds of prisoners or allowing them to die because of overcrowding in the aftermath of the defeat of the Taliban.