At least 12 people were killed at the beachside Elite Hotel in Somalia, in addition to five militants.
Somali special forces were in a siege at the hotel in the capital Mogadishu that was stormed by armed al-Shabab militants.
The attackers detonated a car bomb outside the hotel on Sunday before storming it and seizing hostages.
The recently built hotel is owned by an MP and is popular with Somali politicians. The privately-owned Somali news website Dhacdoone described it as one of the most heavily guarded facilities in Mogadishu.
Security forces sealed off the hotel and exchanged fire with the gunmen inside. Four hours later, government spokesman Ismael Mukhtaar Omar tweeted that the siege was over and all the gunmen had been killed.
A senior official from the information ministry and another official from the defence ministry are reported to be among the dead, along with three hotel guards. Dozens more people were reported to be wounded.
More than 200 people were rescued from the hotel, according to the government spokesman.
Al-Shabab, which is linked to al-Qaeda, has been waging a brutal insurgency in Somalia for more than a decade.
It has been pushed out of Mogadishu by government and African Union troops, but the group still carries out bombings and assassinations in the city.