The attack began at 09:00 local time (04:30 GMT) when one militant blew himself up at the southern gate of the hospital – which is near the US embassy – and three other attackers entered the compound.
They entered the second and third floors of the hospital carrying small arms and hand grenades and began shooting.
One hospital staff member who was able to get out saw an attacker “wearing a white coat holding a Kalashnikov and opening fire on everyone, including the guards, patients and doctors”.One employee wrote on Facebook: “Attackers are inside the hospital. Pray for us.”
One of the gunmen has been killed and the others were hiding under stairs and in bathrooms, a defence spokesman said. One soldier was also killed and three others wounded.
Patients have been evacuated via emergency exits.
At least three dead and more than 60 wounded, most of them hospital staff, have been taken to other hospitals, the health ministry and local media said.
Afghanistan’s de-facto deputy leader Abdullah Abdullah also condemned the attack on Twitter and vowed to “avenge the blood of our people”.
Image captionSmoke billowed from the hospital roof during the attack
Image captionPolice have sealed off the area
IS has been active in Afghanistan since 2015 and has carried out a number of attacks.
It claimed responsibility for a suicide attack at Kabul’s Supreme Court last month that killed 22 people.
The group’s so-called Khorasan Province, which covers Afghanistan and Pakistan, has recently stepped up activity in both countries.
The Taliban has also been carrying out attacks, killing 16 people in Kabul in suicide attacks a week ago, after beginning its Spring offensive early.