The death toll in the armed siege on a hotel in Somalia's seaside capital has risen to 15, said a police officer. The deceased included civilians, guards and militants.
Gunmen on Saturday stormed Nasa-Hablod Hotel in Mogadishu, taking guests hostage and "shooting at everyone they could see," witnesses said.
Police said at least four gunmen were involved in the attack, and two were killed.
Later security forces pursued the grenade-throwing assailants to the top floor and ended the hours-long assault, according to police.
"We have finally ended the siege. The last remaining militants were killed on the top floor," police Captain Mohamed Hussein said after security forces cornered the gunmen, who had set up sniper posts on the roof of the hotel.
The deaths included women who were selling khat, a stimulant leaf popular with Somali men, outside the hotel, he said.
The Al Qaeda-affiliated Al Shabab militant group claimed responsibility for the latest in a series of hotel attacks in Mogadishu, one that began with a powerful explosion at the entry gate of the hotel.
Security forces rescued most of the hostages; it was not clear whether any were killed. Police and medical workers said another nine people were wounded in the assault.
Police said the attack began when a suicide bomber detonated an explosives-laden vehicle at the hotel entrance, ripping off its gate.
Gunmen fought their way inside, and a witness said they began shooting randomly at hotel guests.
Blood was splattered on the hotel floor. The bodies of two men, including one thought to be a hotel guard and an attacker dressed in a military uniform, lay on the first floor.
Officers said some people had managed to escape through the rear of the building.
Bullets pockmarked the hotel walls. Security forces combed through the dark hotel rooms, searching for explosives.
A witness, Ali Mohamud, said the attackers randomly shot at guests. "They were shooting at everyone they could see. I escaped through the back door," he said.
Yusuf Ali, an ambulance driver, told The Associated Press he evacuated 11 people injured in the attack to hospitals. "Most of them were wounded in crossfire," he said.
The United States and other Western countries have been among the biggest donors to the government in Mogadishu as it slowly rebuilds after years of conflict and prepares for parliamentary and presidential elections later this year.
"We strongly condemn this attack," a US State Department official said in a statement. "We remain committed to Somalia's security and stability, and are proud to stand side-by-side with Somalia in the fight against terrorism."
The vote planned for August will be by limited franchise rather than one-person-one-vote, which officials and diplomats say would be too difficult while still fighting an insurgency.
The Somalia-based Al Shabab has been waging a deadly insurgency across large parts of Somalia and often employs suicide car bomb attacks to penetrate heavily fortified targets in Mogadishu and elsewhere.
In early June, an overnight siege by militants at another hotel in the capital killed least 15 people, including two members of parliament. Al Shabab claimed responsibility for that attack as well.
The latest attack comes as the Muslims in Somalia and around the world observe the holy month of Ramadan.
Militants in the region often step up attacks during the fasting month, frequently picking targets where people gather just before or after breaking the fast.
The assaults in the capital have highlighted the challenges facing the Somali government and African Union forces that are struggling to secure the country.
An attack on another Mogadishu hotel and public garden in February killed at least nine civilians.
A car bomb outside a restaurant in the capital in April killed at least five.
The African Union force faces shrinking resources after the European Union recently cut its funding to the AU mission in Somalia by 20 percent.
Citing that cut, Uganda's military chief said Friday his country plans to withdraw its more than 6,000 troops from the AU force in Somalia by December 2017.