At least 11 people were killed at the beachside Elite Hotel, in addition to five militants, according to a government spokesman.
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 officials.
Witnesses said the initial blast was heard across Mogadishu and there was chaos as people fled the area.
A senior official from the information ministry and another official from the defence ministry are reported to be among the dead. Dozens more people were reported to be wounded.
More than 200 people were rescued from the hotel, according to the government spokesman.
The privately-owned Somali news website Dhacdoone described the hotel as one of the most heavily guarded facilities in Mogadishu.
An earlier statement posted online and attributed to al-Shabab said: “The mujahideen have launched an operation consisting of martyrdom [suicide bombing] and a commando raid against a hotel belonging to an MP from the apostate group [Somali government].”
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.
Over the past two months attacks by the jihadist group have increased in the capital.
Last week a shootout between jailed al-Shabab members and security officers at a prison claimed at least 20 lives.
The militants – who had managed to obtain weapons – had tried to escape from a heavily guarded prison in Mogadishu.
Stories That May Interest You:
Fuel tanker blast kills 57 in Tanzania
7-hour siege at Somali hotel ends with10 deaths
Rwanda launches first ‘Made in Africa’ smartphones
Two Nigerians bag 14-year jail term for defrauding US Embassy of 50m
Video: South Africa Pastor Collapses and Dies When giving Sermon In Church
Gambian Soldier: I killed 30 Ghanaians
Former Ivorian Prime Minister Guillaume Soro jailed 20 years for corruption
Cameroon's govt proposes special status for Anglophone regions, releases prisoners
Africa's favorite smartphone maker is now worth $4 billion
Mozambican navy intercepts '1.5 tonnes of heroin'