At least 27 people were killed in an attack on a political rally in Kabul today, officials said, in the deadliest assault in Afghanistan since the US signed a withdrawal deal with the Taliban.

The attack highlights the glaring lack of security in the heavily fortified Afghan capital just 14 months ahead of the scheduled withdrawal of all foreign forces under an agreement signed on February 29 by the US and the Taliban.

Interior ministry spokesman Nasrat Rahimi said women and children were among the dead with an additional 29 wounded, adding that "special forces units are carrying out clearance operations against the attackers".

"The figures will change," he said.

Nizamuddin Jalil, a health ministry official, gave a slightly higher toll, saying 29 people had been killed and 30 others wounded.

The Taliban immediately denied responsibility for the assault, which occurred at the commemoration ceremony for Abdul Ali Mazari -- a politician from the Hazara ethnic group, most of whom are Shiite.

An Islamic State group-claimed attack on the same ceremony last year saw a barrage of mortar fire kill at least 11 people.

Rahimi had earlier said that gunfire had erupted from a construction site near the ceremony in the city's west, which is largely Shiite.

Photos on social media showed several dead bodies being collected after the attack.

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 to reporters 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.

- Continued violence -

The incident 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 US withdrawal hinges to a great extent on the Taliban being able to control jihadist forces such as the Islamic State group.

If such groups remain, so too does the American military.

Since the much-trumpeted deal signing, 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.

IS, 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 Shiite 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 remains in Afghanistan, notably in eastern Kunar province near the Pakistan border, which also neighbours Nangarhar, as well as in Kabul.