KABUL - A suicide bomber on Wednesday killed at least 31 people, many of them teenagers, after detonating a device among a crowd of people in Kabul who were celebrating the Persian new year holiday, officials said.

There were distressing scenes at the hospital opposite the blast site where grief-stricken relatives screamed as they clutched and hugged the bloodied bodies of their loved ones, on what is normally a day of celebration for Afghan families.

The Islamic State group's local franchise in Afghanistan claimed responsibility for the assault in the heavily Shiite neighbourhood - the fifth suicide bombing in the Afghan capital in recent weeks - via the messaging app Telegram.

Another 18 people were wounded in the blast interior ministry spokesman Nasrat Rahimi said, "all of them civilians".

There were fears the figure could rise, however, with the health ministry giving a higher toll of 31 people killed and 52 wounded.

The bomber, who was on foot, detonated his device in front of Kabul University and the hospital that was opposite, Rahimi said. The blast could be heard several kilometres away.

Witnesses told police the bomb had been hidden inside a drum carried by the attacker, which detonated as onlookers got closer, Kabul police spokesman Basir Mujahid told AFP.

The blast occurred less than 200 metres from the Karte Sakhi shrine where many Afghans gather every year to mark Nawrooz, which is the traditional Persian new year holiday but is considered un-Islamic by Muslim fundamentalists.

The bomber had been unable to reach it due to heavy security for Nawrooz, so he "detonated himself among teenagers returning from there", Kabul police chief Mohammad Daud Amin told Tolo News.

Bloodstains could be seen among scattered shoes and other belongings at the site of the attack.

Outside the hospital morgue, a visibly distressed man knelt next to several bodies, cursing the Afghan government, before he was pulled away by a relative and a medical worker.

Another body lay on a stretcher in the hospital compound, a pair of red, white and blue tennis shoes poking out from underneath a covering.

IS, which regularly targets Shiites in an attempt to stir up sectarian violence in Sunni-majority Afghanistan, has attacked the same shrine once before.

In October 2016 IS gunmen killed 18 people gathered to mark Ashura, an important date for many Muslims, especially Shiites.

President Ashraf Ghani, whose government has been repeatedly lambasted for its inability to protect its citizens, condemned the latest attack in a statement as a "crime against humanity".

Taliban and IS militants have increasingly targeted the war-weary city in recent months as US and Afghan forces ramp up air strikes and ground offensives against the groups. Wednesday's blast comes days after a Taliban suicide attacker blew up a bomb-laden car in Kabul, causing multiple casualties.

Some Western and Afghan security experts believe the Haqqani Network, a hard-line wing of the Taliban, has been behind some of the attacks in Kabul in recent months, including those claimed by IS.

The Taliban, Afghanistan's largest militant group, faces growing pressure to take up a recent offer by Afghan President Ashraf Ghani of peace talks to end the 16-year war. So far it has given only a muted response.

This latest suicide attack underscores the growing challenge facing Afghan and foreign forces to protect the already heavily militarised city.

General John Nicholson, who leads US and NATO forces in Afghanistan, recently told reporters that protecting Kabul was a priority for foreign troops.

But he acknowledged that preventing further attacks would be challenging in the sprawling city that is poorly mapped and extremely porous.

The latest attack comes as US Chairman of Joint Chiefs of Staff General Joseph Dunford visits Afghanistan to assess the military campaign against insurgents - weeks before the start of the spring fighting season, which is expected to be particularly bloody this year.

Despite calls for the Taliban to sit down with the Afghan government, the group - which has been resurgent since the withdrawal of US-led NATO combat troops at the end of 2014, taking back territory and devastating Afghanistan's beleaguered security forces - appears to have few reasons to negotiate.

In October, insurgents controlled or influenced nearly half of Afghanistan's districts - double the percentage in 2015, the US government's office of the Special Inspector General for Afghanistan Reconstruction said in January.

Over the same period, the watchdog said, the number of districts under Afghan government control or influence fell to its lowest level since December 2015.