A suicide bombing followed by gunfire as Shia Muslims gathered for Friday prayers at a mosque in Kabul killed at least 28 people, with the Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group claiming responsibility.

Mohammad Salim Rasouli, the chief of Kabul's hospitals, announced the new death toll on Saturday, as burials began. He said at least 50 people were injured.

Wailing mourners gathered at the mosque on Saturday to lay the bodies of the dead side by side in graves.

"We used to attend ceremonies such as Ashura together in this mosque, but today I am burying their bodies here," Hussain Ali, who lost a friend in the attack, told the AFP news agency.

"This is not the first time, it keeps happening. The government has failed to provide us security. Even today in this ceremony people are worried lest something will happen," he added.

Four hours of gunfire, explosions

After the blast at the Imam Zaman mosque in Afghan capital's Qala-Najara neighbourhood, gunmen stormed in and began shooting.

Terrified worshippers endured about four harrowing hours of gunfire and explosions during the afternoon before the four attackers were killed.

The cleric who was performing the prayers was among the dead, said Mir Hussain Nasiri, a member of Afghanistan's Shia clerical council.

The mosque is large and can accomodate up to 1,000 people.

Policemen made an attempt to enter the mosque but withdrew after one of the attackers set off an explosion, said police official Mohammad Sadiq Muradi.

"The attackers are slaughtering people like sheep, but there's no one to go and rescue them," Murtaza, a young boy whose parents were trapped inside, said as the assault unfolded. "A lot of people are on the ground, and no one is trying to rescue them."

A sprawling cavernous prayer hall dominates the main floor. The second floor is where the women pray.

Nasiri said when police initially sought to get into the mosque, the attackers blocked the door leading to the second floor, which he said would mean they held the women hostage.

Al Jazeera's Jennifer Glasse, reporting from the scene, quoted eyewitnesses as saying the assailants had run out of ammunition and started stabbing worshippers with knives. Some of the victims included children and women.

"It was a busy time, in the middle of Friday prayer as the attack took place," said Glasse.

ISIL's affiliate in Afghanistan claimed responsibility. ISIL-linked Aamaq website said on Friday two of its fighters carried out the assault. It did not give further details.

The attack was the latest by ISIL to hit the Afghan capital. Last month it hit the Iraqi embassy in Kabul and afterwards issued a warning to all Shia in Afghanistan, saying its cadres would attack Shia places of worship.

Within days of the embassy attack, ISIL also took responsibility for a suicide assault on a Shia mosque in western Herat province that killed 32 people.