The Central Hotel, often frequented by politicians, was hit by a car bomb and a suicide attack. Gunmen then stormed the hotel mosque and opened fire during Friday prayers.
An MP and Mogadishu's deputy mayor were among the dead, the government says.
Islamist militant group al-Shabab has said it was behind the attack.
The al-Qaeda linked group has been driven out of the country's major towns but still controls many rural areas in the south.
The BBC's Mohamed Moalimu in the city says the area around the hotel has been cordoned off.
"First the car bomb exploded at the gate of the hotel, then a suicide bomber blew himself up in the hotel compound," police Major Nur Mohamed told Reuters.
Information Minister Mohamed Abdi Hayir Mareeye told the BBC that Somalia's deputy prime minister and other ministers had been at the hotel at the time but had survived the attack.
An al-Shabab spokesman told BBC Somali analyst Mary Harper it had killed the officials while they were praying because they were "apostates".
It has previously said it would target members of the government.
Earlier this month, al-Shabab shot dead an MP in a drive-by shooting in Mogadishu.
Some 20 people, including senior officials, have been killed in an attack on a hotel in the Somali capital, witnesses have told the BBC.