The assault was continuing and some al-Shabab fighters remained in the Ambassador Hotel, according to police captain Mohamed Hussein.
The hotel is frequented by government officials and business executives.
“At least two gunmen are still holed up inside the building now,” Mr Hussein said.
Two members of parliament were among the dead, he said.
The attack began when a suicide bomber detonated an explosives-laden vehicle at the hotel’s gates. Fighters on foot then forced their way into the hotel.
The attack comes on the eve of the Muslim holy month of Ramadan, during which extremists often step up attacks in the volatile east African country.
The body of a suspected extremist lay outside the hotel, which was surrounded by heavily armed soldiers.
Witness Yasin Abdi said he saw security forces escorting some people from the three-storey hotel.
Somalia’s elite forces used rocket-propelled grenades and machine guns mounted on cars to fight assailants who took up positions on the hotel’s second floor.