Afghan forces said they retook a prison in the country's east on Monday afternoon, following an hours-long battle a day after the facility was targeted by the Islamic State group in an attack that killed 29 people.
The prison is believed to be holding hundreds of IS members.
The attack highlighted the challenges ahead for Afghanistan, even as US and NATO forces begin to withdraw following America striking a peace deal with the Taliban.
Defence Ministry spokesman Fawad Aman said the prison was taken back in the afternoon. The fighting also left at least 50 wounded.
Even as Afghan troops seized the prison in Jalalabad, the capital of Nangarhar province, some 115 kilometres (70 miles) east of Kabul, IS militants continued to fire on Afghan security forces from a nearby neighbourhood.
As security forces swept through the prison, they found the bodies of two Taliban prisoners apparently killed by the Islamic State group, showing the tensions between the two militant factions battling each other in eastern Afghanistan.
The 29 dead included civilians, prisoners, guards and Afghan security forces, said Attaullah Khogyani, the provincial governor's spokesman.