Dozens of people were killed when gunmen opened fire at a political rally in Kabul on Friday, in the deadliest assault in Afghanistan since the US signed a withdrawal deal with the Taliban.
The attack, claimed by the Islamic State group, highlights a glaring lack of security in the Afghan capital just 14 months ahead of the scheduled withdrawal of all foreign forces.
It also calls into question a key element of the US-Taliban deal signed February 29 -- whether the Taliban are capable of stopping jihadists such as IS from running amok in Afghanistan after US forces pull out.
In a statement, IS said two brothers had targeted a "gathering of apostates" with machine guns and grenades.
The gunmen inflicted devastating carnage at the crowded event in west Kabul, killing 32 people and wounding 58 others, health ministry spokesman Wahidullah Mayar told AFP.
Interior ministry spokesman Nasrat Rahimi put the toll at 29 dead, with an additional 61 wounded. He said special forces units had carried out clearance operations, eventually killing the two gunmen.
The assault occurred at a commemoration ceremony for Abdul Ali Mazari -- a politician from the Hazara ethnic group.
The Sunni-extremist IS had claimed an attack on the same ceremony last year, when a barrage of mortar fire killed at least 11 people.
Rahimi said gunfire had erupted from a construction site near the ceremony.
Photos on social media showed several dead bodies being collected from the scene.
President Ashraf Ghani condemned the massacre, calling it a "crime against humanity".
The ceremony was attended by many of the country's political elite, including Afghanistan's chief executive Abdullah Abdullah.
The interior ministry later confirmed that "all the high-ranking officials were safely evacuated from the scene".
"We left the ceremony following the gunfire, and a number of people were wounded, but I do not have any reports of martyred people for now," Hazara leader Mohammad Mohaqiq told Tolo News.
The mass shooting comes less than a week after the US and Taliban signed a deal that would pave the way for the complete withdrawal of foreign troops in 14 months.
The withdrawal hinges to a great extent on the Taliban being able to control jihadist forces such as Al-Qaeda and IS.
If such groups remain, so too does the US military.
A spokesman for US Forces-Afghanistan said the response to Friday's attack was "Afghan-led", but US personnel provided medical assistance to the victims.
US Secretary of State Mike Pompeo insisted that despite the attack, violence in Afghanistan was still "significantly down".
"The violence levels, they're still lower than they have been in the last five or six years," Pompeo told CNBC news.
"We see the path forward towards a peace and reconciliation opportunity."
But since the much-trumpeted deal signing in Doha last weekend, fighting has continued to rage across Afghanistan, casting a pall over hopes the agreement would lead to a reduction in violence and talks between the Taliban and the Afghan government.
Afghan government officials and the Taliban are supposed to meet in Oslo next week, but discussions look likely to be delayed by a disagreement over a mass prisoner release.
The US-Taliban deal states that the Afghan government should release as many as 5,000 Taliban prisoners before the supposed start date of the talks of March 10. President Ghani however has rejected that commitment.
The blame game got underway Friday, when the Taliban's political spokesman Suhail Shaheen said the insurgents were ready for talks -- but only if the prisoners were released.
"If the negotiations are delayed beyond the stated date, the responsibility will rest with the others," Shaheen said on Twitter.
The Islamic State group, which follows a radical Sunni interpretation of Islam, first became active in Afghanistan in 2015 and for years held territory in the eastern province of Nangarhar.
It has claimed responsibility for a string of horrific bombings, including several in Kabul targeting the city's Shia community.
In recent months the group has been hit by mounting setbacks after being hunted for years by US and Afghan forces along with multiple Taliban offensives targeting their fighters.
Still, IS fighters remain in Afghanistan, notably in eastern Kunar province near the Pakistan border, which also neighbours Nangarhar, as well as in Kabul.