Police said at least seven people had died and 10 others were wounded. Gunfire echoed round the seaside city after the blast and ambulances raced to the scene.
"We attacked the hotel which was frequented by the apostate government members," al Shabaab military operations spokesman Sheikh Abdiasis Abu Musab told Reuters, adding that the group's fighters were inside the building.
"Those who died included civilians and hotel guards," police major Ali Hassan told Reuters.
"We have rescued many people from the back door. No one can enter the building from the front or near the front. There are snipers there," he said as fighting continued.
Earlier, another police officer said the initial blast was caused by a suicide bomber before fighters stormed into the Nasahablood hotel. There was a heavy exchange of gunfire.
Muslims in Somalia and around the world are observing Ramadan. In previous years, al Shabaab has often intensified attacks during the fasting month, often picking targets where people gather just before or after breaking the fast.