Islamic State has claimed responsibility for a suicide attack on a crowded Shi'ite mosque in Kabul that killed more than 30 people and wounded dozens in its third major attack on minority Shi'ites in the Afghan capital since July.
Officials said the attacker entered the Baqir-ul-Olum mosque shortly after midday on Monday as worshippers gathered for Arbaeen, a Shi'ite ritual marking the end of a 40-day mourning period for the 7th century death of Imam Hussein, grandson of the Prophet Mohammad.
A statement in Arabic from Islamic State's Amaq news agency said one of its fighters had targeted the mosque.
Bloody sectarian rivalry between Sunni and Shi'ite Muslims has been relatively rare in Afghanistan, a majority Sunni country, but the attack underlines the deadly new dimension that growing ethnic tension could bring to its decades-long conflict.
Fraidoon Obaidi, chief of the Kabul police Criminal Investigation Department, said at least 27 people were killed and 35 wounded, while the United Nations said at least 32 had been killed and more than 50 wounded, including many children. It described the attack as "an atrocity".
One survivor told Afghanistan's Ariana Television that around 40 dead and 80 wounded had been taken from the building before rescue services arrived at the scene.
Another witness said he had helped carry 30-35 bodies from the mosque.
Islamic State, based mainly in the eastern state of Nangarhar on the border with Pakistan, has gradually expanded its reach since emerging in Afghanistan last year.
The Taliban, itself fiercely opposed to Islamic State, had already denied any involvement.
Officials said the attack was a deliberate attempt to stoke sectarian tensions.
Any resurgence of sectarian or ethnic violence could threaten the fragile stability of the government headed by President Ashraf Ghani, who described the mosque blast as an attempt "to sow seeds of discord".