Three people were killed when mortar shells exploded outside a ceremony in the Afghan capital Kabul attended by the country’s chief executive and a former president.
The ceremony commemorated the 1995 death of prominent minority Hazara leader Abdul Ali Mazari, who was killed by the Taliban.
Afghan chief executive Abdullah Abdullah and ex-president Hamid Karzai attended the gathering. Both men were unharmed, but three others were killed and 31 people were injured in the attack launched from a house near the ceremony.
Security forces battled for several hours with militants holed up in the house, and two insurgents were eventually killed and one person was arrested.
The Islamic State group has claimed responsibility for the attack.
Presidential candidate and former Afghan national security adviser Hanif Atmar tweeted that eight of his personal guards were injured in the “horrid and unforgiveable” attack.
Another presidential candidate, Latif Pedram, was injured but his condition is not known.
Hundreds of people attended the ceremony in a large hall on the western edge of Kabul in the Dasht-e-Barchi neighbourhood.
Azizullah Amini, who attended the event, said he heard at least four explosions and the hall shook as if something was slamming into the ground outside the building.
The ceremony quickly ended as people were rattled by the blasts.
IS said on an affiliated website that it had targeted a “Shiite celebration attended by senior government officials”.
Meanwhile, IS has claimed responsibility for an attack on Wednesday on a construction company in eastern Nangarhar province that killed at least 17 people and triggered an hours-long gun battle with Afghan forces.
Elsewhere in Afghanistan, the Taliban waged a blistering four-hour battle with security forces on Wednesday night in northern Kunduz province, in the Qalay Zul district, killing seven policemen.
Early on Thursday, the Taliban killed four Afghan border patrol officers in western Herat province, near the border with Iran.