More than 30 people have been killed after attackers dressed as doctors stormed the largest military hospital in Kabul, Afghan officials say.
Militants armed with guns and grenades gained entry after one detonated explosives at a hospital gate and then opened fire on staff and patients.
Commandos who landed on the Sardar Daud hospital roof killed all four attackers after several hours of fighting.
The so-called Islamic State (IS) group has claimed the attack.
The Taliban has denied any involvement.
More than 50 people were also wounded, the defence ministry said.
President Ashraf Ghani said the attack at the 400-bed hospital “trampled all human values”.
“In all religions, a hospital is regarded as an immune site and attacking it is attacking the whole of Afghanistan,” he said.
The attack began at 09:00 local time (04:30 GMT). 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.”
TV pictures showed people hiding from the gunmen on ledges outside windows on upper floors of the building.
More than six hours after the attack began, interior ministry spokesman Sediq Sediqqi tweeted that special forces had ended their operation and all the attackers were dead.
The IS-affiliated Amaq news agency shared two images via the Telegram messaging app that appeared to show one of the militants taking part in the assault and a number of dead bodies.
Afghanistan’s de-facto deputy leader Abdullah Abdullah also condemned the attack on Twitter and vowed to “avenge the blood of our people”.
BBC Afghan’s Inayatulhaq Yasini says that, if this is confirmed an IS attack, it would be the first time its jihadists had used the Taliban-style tactic of first blowing the gates and then sending another group of attackers into the targeted building.
It would also show, he says, that despite the Afghan government’s claim that IS is on back foot, its militants are increasing their ability to carry out high-profile attacks that require a lot of planning and resources.
IS announced it was moving into Afghanistan and Pakistan when it declared its so-called Khorasan Province in 2015 and has since carried out a number of attacks.
In July 2016, a suicide bomb attack on a rally in Kabul killed about 80 people.
Three months later, two similar attacks during the religious festival of Ashura claimed about 30 lives and in November 2016 an attack at a mosque in Kabul killed more than 30.
IS also claimed a suicide attack at Kabul’s Supreme Court last month that killed 22 people and has stepped up activity in both Afghanistan and Pakistan.
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.