A suicide bomb and gun attack claimed by the Islamic State group on a Shia mosque in Kabul killed 20 people and wounded scores more on Friday, officials said, the latest assault to highlight deteriorating security in Afghanistan.
Gunshots and explosions could be heard during the attack that lasted around four hours and witnesses reported seeing worshippers smash windows to escape.
The mosque, in a residential area in the north of the city, was believed to have been packed with dozens of men, women and children when the assailants struck during Friday prayers.
"We have 20 killed and more than 50 wounded," Mohammad Ismail Kawoosi, a health ministry official, told AFP, without specifying how many were civilians.
Heavily armed security forces stormed the building and rescued more than 100 worshippers, according to the interior ministry, which had initially put the death toll at 12, including 10 civilians and two security force personnel. 
It had also put the number of wounded at more than 40 civilians and seven security forces. 
"The attack is over and the site has been cleaned up by our police," deputy spokesman Najib Danish told AFP, confirming three attackers were killed by security forces.
He told Afghan media that police "blew up a wall behind the building to get in and rescue people".
Kabul police spokesman Abdul Basir Mujahid told AFP a suicide bomber "detonated himself inside the mosque" .
People gathered outside had tried to call women and children trapped inside but their mobile phones were not responding, an AFP reporter at the scene said.
"Our relatives have been stranded inside the mosque... We believe they have been held hostage by the gunmen. We are very concerned about their safety and may God help us and rescue our loved ones," one of the onlookers said. 
Eyewitnesses described horrific scenes inside the mosque as the attackers ran short of bullets and began "using knives to stab worshippers".
Others said the attackers had been armed with rocket propelled grenade launchers and had holed themselves up in the women's section of the mosque.
The Islamic State claimed responsibility for the deadly assault via its propaganda agency.
"Two 'inghimasi' of the Islamic State carried out an attack on a husseiniya (Shia place of worship) in the Khair Khana sector of the Afghan city of Kabul," Amaq said, using the terms for suicide bombers who set off explosive vests as a last resort against gunfire.
Pools of blood  
The assault underscores spiralling insecurity in Afghanistan as a resurgent Taliban steps up offensives across the country, while the Islamic State group, known for carrying out sectarian attacks, expands its Afghan footprint.
It comes just days after US President Donald Trump cleared the way for thousands more American troops to be deployed in the war-torn country.
More than 10 ambulances were at the scene to take the wounded to local hospitals. Some relatives flocked to a nearby private hospital to search for loved ones who had been in the mosque at the time of the attack. 
Pools of blood could be seen at the entrance to the medical facility. 
Shiites, a minority of around three million in overwhelmingly Sunni Afghanistan, have regularly been targeted by IS jihadists recently. They accuse police and troops of failing to protect them.
IS has claimed responsibility for a series of attacks killing dozens of Shias in Kabul over the past year, including twin explosions in July 2016 that ripped through crowds of Hazaras, killing at least 85 people and wounding more than 400.
Earlier this month 33 worshippers were killed and 66 wounded in a suicide attack claimed by IS on a Shia mosque in the western Afghan city of Herat.
Related Story