The police blew up two car bombs between the Sahafi Hotel and another behind the hotel.
Colonel Qasim Ahmed Roble, spokesman for the Somali police, told reporters that five assailants tried to storm the hotel, but were shot dead by the police.
He said fifty-two Somali officials had been rescued from Sahafi Hotel and Hayat Hotel.
Abdiaziz Ibrahim, a former Ministry of Internal Security spokesman who was at the scene, told CNN that the attacks lasted 20 minutes and took place "one after another".
One of the victims was the owner of the hotel, said Ibrahim.
"Those who made the attack were dressed in police uniform but were al-Shabab attackers," he said.
"Such despicable terrorist attacks will in no way undermine the resolve of the Somali people to pursue the priorities of state-building, economic recovery and security," UNSG Deputy Special Representative for Somalia Raisedon Zenenga said in a statement.