A Taliban assault on the Intercontinental Hotel in Kabul killed at least 18 people, including 14 foreigners, officials said, although the casualty toll expected to rise.
Afghan security forces battled for more than 13 hours before the last attacker was slain on Sunday at the heavily guarded luxury hotel popular with foreigners and Afghan officials.
Interior ministry spokesman Najib Danish said the 18 killed included 14 foreigners and a telecommunications official from Farah province who was attending a conference.
Eleven of the 14 foreigners killed were employees of KamAir, a private Afghan airline.
Ukraine's foreign minister said six of its citizens were killed in the attack.
Ten other people, including six from the security forces, were wounded and more than 150 people, including 41 foreigners, were rescued from the hotel, Mr Danish said.
The raid was the latest in a long series of attacks which have underlined the city's precarious situation and the ability of militants to mount high profile operations aimed at undermining confidence in the western-backed government.
he Taliban claimed responsibility for the attack, which began at around 9pm on Saturday. Even after officials said the attack was over, sporadic gunshots and explosions could be heard from the site.
It is unclear exactly how many gunmen were involved. Mr Danish said three gunmen were killed, while witnesses said four were involved and the Taliban said five.
Abdul Rahman Naseri, a guest who was at the hotel for a conference, was in the lobby when he saw four insurgents dressed in army uniforms.
"They were shouting in Pashto, 'Don't leave any of them alive, good or bad. Shoot and kill them all,' one of them shouted," Mr Naseri said.
"I ran to my room on the second floor. I opened the window and tried to get out using a tree but the branch broke and I fell to the ground. I hurt my back and broke a leg."
As day broke on Sunday, thick clouds of black smoke could be seen pouring from the building. Several armoured US military vehicles with heavy machine guns could be seen close to the hotel along with Afghan police units.
Hotel manager Ahmad Haris Nayab, who escaped unhurt, said the attackers had got into the main part of the hotel through a kitchen before going through the hotel, with many guests trapped in their rooms.
"When the sixth floor caught fire this morning, my roommate told me, either burn or escape," said Mohammad Musa, who was hiding in his room on the top floor when he heard gunfire.
"I got a bed sheet and tied it to the balcony. I tried to come down but I was heavy and my arms were not strong enough. I fell down and injured my shoulder and leg."
The raid came just days after a US embassy warning of possible attacks on hotels in Kabul.
The government-run Intercontinental Hotel, an imposing 1960s structure set on a hilltop and heavily protected like most public buildings in Kabul, was previously attacked by Taliban fighters in 2011.
It is one of two main luxury hotels in the city and had been due to host an information technology conference on Sunday. More than 100 IT managers and engineers were on site when the attack took place, Ahmad Waheed, an official at the telecommunications ministry, said.
The attack, just days after a UN Security Council visit to Kabul to allow senior representatives of member states to assess the situation in Afghanistan, may lead to a further tightening of security in Kabul.
Large areas of the city centre are already closed off behind high concrete blast walls and police checkpoints but the ability of the attackers to get into a well-protected hotel frequented by both government officials and foreigners demonstrated how difficult it remains to prevent high profile attacks.
Mr Danish said a private company had taken over security of the hotel about three weeks ago.
Although the Nato-led Resolute Support mission in Afghanistan says the Taliban has come under pressure after the US increased assistance to Afghan security forces and stepped up air strikes against insurgents, security remains precarious.
As pressure on the battlefield has increased, security officials have warned that the danger of attacks on high-profile targets in Kabul and other cities would increase.
After repeated attacks in Kabul, notably an incident last May in which a truck bomber killed at least 150 people outside the German embassy, security has been further tightened.
While it shares the same name, the hotel in Kabul is not part of InterContinental Hotels Group (IHG), which issued a statement in 2011 saying that "the hotel Inter-continental in Kabul is not part of IHG and has not been since 1980".