Gunmen attacked a ceremony in Kabul on Friday, killing at least 27 people in the first major attack on the Afghan capital since the United States reached an agreement with the Taliban to withdraw US troops.
The Taliban, the largest Islamist militant group in Afghanistan, said in a statement they were not involved in the attack. A top Afghan political leader, Abdullah Abdullah, was present at the event but escaped unharmed.
Fifty-five people were wounded, according to the Afghan ministry of health.
"The attack started with a boom, apparently a rocket landed in the area, Abdullah and some other politicians ... escaped the attack unhurt," Abdullah's spokesman, Fraidoon Kwazoon, who was also present, told Reuters by telephone.
Broadcaster Tolo News showed live footage of people running for cover as gunfire was heard.
A health ministry spokesman said the casualty toll could rise. Dead and wounded were being ferried from the site by ambulance.
A NATO source said that the death toll was slightly higher: more than 30 killed, with 42 wounded, 20 of whom were in a serious condition.
Afghan defence forces continued to fight gunmen throughout the day, finally securing the area by killing about three gunmen in the late afternoon, according to ministry of interior spokesman Nasrat Rahimi.
The gathering had marked the anniversary of the death of Abdul Ali Mazari, an ethnic Hazara leader who was killed in 1995 after being taken prisoner by the Taliban. Several people were killed in a similar attack on the same commemoration last year, which Islamic State said was carried out by its militants.
President Ashraf Ghani tweeted that the attack was "a crime against humanity and against the national unity of Afghanistan".
Abdullah, who escaped, was runner-up in the last three Afghan presidential elections, each of which he disputed. He has served as chief executive of a coalition government since 2014 and is also a former foreign minister.
Ghani said he had telephoned Abdullah, his longtime political rival. Abdullah is contesting an Electoral Commission announcement last month declaring Ghani the winner of September's presidential election.
Dozens of relatives gathered at the morgue of a hospital not far from the blast, with many breaking down in tears as they waited to identify their loved ones.
Ambulances and stretchers bustled back and forth at the hospital to deliver the wounded for treatment.
"I was at the ceremony when gunshots started. I rushed towards the door to get out of the area but suddenly my foot was hit by a bullet," Mukhtar Jan told Reuters from a stretcher at the hospital.
Ali Attayee, at the hospital to support his wounded brother, said: "Those who committed this crime want to destroy our people at this juncture in society, we're sorry for those committing such crimes."
Representatives of the United States, European Union and NATO condemned the attack.
"We strongly condemn today's vicious attack...We stand with Afghanistan for peace," the United States charge d'affaires in Kabul Ross Wilson wrote on Twitter.
The attack was one of the largest on civilians in Afghanistan in a year.
"Horrific attack in Kabul today...heartbreaking and unacceptable. We are tired of war and violence," said Shahrzad Akbar, head of the Afghanistan Independent Human Rights Commission.
Hazaras are mostly Shi'ite Muslims. Minority Shi'ites have been repeatedly attacked by Sunni militants in Afghanistan.
The United States has sought to spearhead efforts towards a lasting peace arrangement. Violence decreased during a seven-day hold-down accord with the Taliban before last Saturday's deal, though the Taliban has since resumed attacks on Afghan forces.