Around 50 others were wounded in the assault on the Sardar Daud Khan hospital, with explosions and gunfire rattling Kabul's diplomatic district as dense clouds of smoke rose in the sky.
Medical staff hunkered down in the hospital wards posted desperate messages for help on social media. Television footage showed some of them trapped on the ledge of a top-floor window.
"Attackers are inside the hospital. Pray for us," a hospital staff member wrote on Facebook.
At least one dead, 35 wounded in Kabul attacks
Hospital administrators told AFP three gunmen wearing white laboratory coats began spraying bullets after a suicide bomber on foot blew himself up at the backdoor entrance, sparking chaos inside the 400-bed facility.
"I saw one of the attackers, armed with an AK-47 and dressed as a doctor, shooting at patients and guards on the third floor," hospital nurse Abdul Qadeer told AFP.
"They shot my friend but I managed to flee... I had to jump over the barbed wire to escape."
At least two other loud explosions – including what the defence ministry called a car bomb in the hospital's parking lot – were heard as Afghan special forces launched a clearance operation that lasted around six hours.
The attackers were gunned down after special forces landed on the roof of the hospital in a military helicopter.
"More than 30 people were killed and around 50 wounded in today's attack," defence ministry spokesman Dawlat Waziri told AFP. "Most of the victims are patients, doctors and nurses."
Afghanistan's warring parties, including government forces, have repeatedly targeted medical facilities, decimating the country's fragile health system and preventing conflict-displaced civilians from accessing life-saving care.
"This is a criminal act. Nothing can justify an attack on hospitals," Afghan Chief Executive Abdullah Abdullah said of the latest attack.
"We will never forgive these criminals. Unfortunately, this attack has resulted in some casualties."
Islamic State group claimed the attack via a verified Telegram account.
Nine killed as militants raid Kabul's American University
The more powerful Taliban said they were not behind the raid. The militant group, Afghanistan's largest, is known to distance itself from attacks on medical facilities or those that result in high civilian casualties.
The assault comes just a week after 16 people were killed in simultaneous Taliban suicide assaults on two security compounds in Kabul.
Dozens of others were wounded as a suicide car bomber struck an Afghan police precinct in western Kabul and a five-hour gun battle ensued after another attacker sneaked in.
In the second attack last week, a suicide bomber blew himself up at the gates of an Afghan intelligence agency branch in eastern Kabul.
The carnage underscores rising insecurity. The country is bracing for an intense fighting season in the spring as the government's repeated bids to launch peace negotiations with the Taliban have failed.
Afghan forces, already beset by record casualties, desertions and non-existent "ghost soldiers" on the payroll, have been struggling to beat back insurgents since US-led NATO troops ended their combat mission in December 2014.
Kabul last month endorsed US General John Nicholson's call for thousands of additional coalition troops to hold off the militants before the spring offensive.
Extra troops were needed to end the stalemate in the war, Nicholson, the top US commander in Afghanistan, told the US Congress in what could be President Donald Trump's first major test of military strategy.
COMMENTS (3)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ