KABUL, Afghanistan — A suicide bomber struck a crowded gathering of Shiite Muslims in the Afghan capital on Monday, officials said, killing at least 30 people in the latest assault against religious minorities here to be claimed by militants loyal to the Islamic State.

The suicide bomber detonated his explosives just as hundreds of worshipers had packed into the Baqir ul-Uloom mosque, in western Kabul. They were commemorating Arbaeen, a Shiite observance of loss and grief that comes 40 days after Ashura, when a grandson of the Prophet Muhammad was martyred. The Islamic State had claimed an attack during that holiday as well, bombing another Shiite shrine in Kabul on the eve of Ashura, and killing at least 14.

Sediq Sediqqi, a spokesman for the Interior Ministry, said that at least 30 people had been killed and at least 40 wounded.

The blast was so powerful that the windows from all three floors of the mosque were blown away. The walls looked as if they had been hosed with blood. Human remains, shoes, bloodied copies of the Quran and broken prayer beads were scattered around the hall.