Gunmen dressed as doctors attacked a military hospital in the Afghan capital and battled security forces in the building for several hours, killing at least 30 people and wounding dozens more in an attack claimed by the Islamic State (IS) group.
A suicide bomber blew himself up at the rear of the 400-bed Sardar Mohammad Daud Khan hospital, across the road from the heavily fortified US embassy, and three attackers with automatic weapons and hand grenades entered the complex, security officials said.
Defence Ministry spokesman Dawlat Waziri said the attack was suppressed by mid-afternoon with all three gunmen killed. Security forces were conducting sweeps through the hospital buildings.
At least 66 wounded, mainly civilians including women and children, were taken to other hospitals, a spokesman for the public health ministry said.
The gunmen, dressed as medical personnel, had taken position on upper floors of the hospital and engaged special forces sent to the scene, officials said.
Security forces blocked off the area around the hospital, near a busy traffic intersection. As fighting went on, a second explosion was heard from inside.
FRANCE 24's expert on jihadist networks, Wassim Nasr, said the IS group had claimed the attack via its Amaq news agency.
Nasr said a spokesman for the Taliban, who were initially suspected of having carried out the attack, had earlier denied the group's involvement.
The raid on the hospital, across the road from the heavily fortified US embassy, underlines warnings by government officials that high-profile attacks in Kabul are likely to escalate this year.
With US President Donald Trump yet to announce his policy for Afghanistan, where the top US commander has said thousands more international troops may be needed to maintain stability, it also underlines the growing threat from the IS group.
The movement, which is opposed to both the Western-backed government and the Taliban, has established a solid presence on the border with Pakistan. But it has also mounted several high-profile attacks on civilian targets in Kabul over the past year, including several on prominent Shiite targets.
The hospital attack drew wide condemnation and President Ashraf Ghani said it "trampled on all human values".
"In all religions, a hospital is regarded as an immune site and attacking it is attacking the whole of Afghanistan."
The NATO-led Resolute Support mission said it was ready to assist Afghan security services.
Witnesses inside the hospital said they were caught by surprise as a gunman dressed in a white doctor's coat took out concealed AK-47 assault rifle and opened fire, killing at least one patient and one hospital worker.
"Suddenly gunfire broke out and a gunman was shooting at everyone," said Zahir Khan, who hid under a table and later escaped. "He was shooting at doctors, patients and visitors."
As the fighting went on, some patients climbed out of the building and could be seen sheltering on window ledges visible from outside the hospital, which treats military casualties from around Afghanistan.
The attack comes just a week after dozens were killed and wounded in coordinated attacks on a police station and an office of the intelligence service in Kabul.
That attack was claimed by the Taliban, who are seeking to expel foreign troops, defeat the US-backed government and reimpose Islamic law after their 2001 ouster.
Away from Kabul, dozens of people have been killed over the past few days in fighting across Afghanistan, from Kunduz and Baghlan in the north to Farah in the southwest and Helmand and Kandahar on the Pakistan border in the south.