Witnesses said the shooting started when a former vice president, Karim Khalili, was delivering his speech to a ceremony in the Afghan capital, organized to commemorate the martyrdom of Abdul Ali Mazari, a prominent minority Shi’ite Hazara politician.
The event was being shown live by Afghan television stations and Khalili could be seen running for cover along with others when the gunfire erupted from a nearby under-construction building.
There were women and children among those killed and injured, and Afghan health officials say they expect the death toll to increase.
Afghan Interior Ministry spokesman Nasrat Rahimi said Afghan security forces later engaged three assailants and killed them in the ensuing hours-long clash to end the siege.
There were no claims of responsibility, and the Taliban insurgency swiftly denied its involvement in the attack.
The ISIS terror group's regional affiliate, known as Khorasan Province or ISKP, has claimed responsibility for previous attacks on Shi’ite gatherings and worship places in Afghanistan.
Afghan Chief Executive Abdullah Abdullah and former president Hamid Karzai were also among guest speakers at Friday’s gathering. Both of them escaped unharmed.
However, a former provincial governor was said to one among those wounded.
President Ashraf Ghani condemned the attack as a "crime against humanity", saying the violence was directed at Afghan national unity.
Last year’s commemoration of Abdul Ali Mazari’s martyrdom anniversary, which is mostly attended by Hazara Afghans, had also come under attack. About a dozen people were killed and many more were injured. That attack was claimed by ISIS.
The ethnic Hazara leader was martyred in 1995 after being taken hostage by Taliban when Afghanistan was in the grip of a deadly civil war.