IS claim responsibility for Afghan hospital raid
IS-linked Amaq media published a statement saying it had carried out the raid on the Sardar Daud Khan hospital.
It posted a picture it claimed on be a militant wearing a surgical mask holed up in the building.
More than 30 people died in the attack, most medical staff and patients.
"Most of the victims are patients, doctors and nurses," ministry spokesman Dawlat Waziri told AFP, adding that four attackers were also killed.
Hospital administrators said the three gunmen wore white laboratory coats during the attack - 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 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 to rein in the attackers.
"Three attackers armed with AK-47s and grenades entered the building. Our commandos are chasing them," ministry spokesman Dawlat Waziri told AFP around four hours after the first explosion.
"One of them has been killed, but two others are still resisting on the sixth and seventh floors of the building. We have evacuated all the patients."All the militants were killed following battles with Afghan security forces at the hospital, close to the US embassy.
Afghanistan has witnessed a growing number of attacks in recent weeks with Taliban insurgents who have targeted a security forces in the country.
Agencies contributed to this story.