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.

In 2015, the Department for Transport said electrification of the whole link - which goes through Manchester, Leeds and York - would be complete by 2022.
Transport Secretary Chris Grayling has since said electrification will instead be used "where it makes a difference".
Shadow rail minister Rachael Maskell has called it "a slap in the face".
In an interview with the Daily Telegraph, Mr Grayling said: "We are not abandoning electrification, what we are doing is using electrification where it makes a difference.
"What we've got on the railways is technology we didn't have five or six years ago."
He said the use of bi-mode trains, which can travel on both electrified and non-electrified sections of a track, meant there were "places on the network you don't actually need to start digging everything up and putting in place overhead cables".
The project to electrify the route between Manchester and Leeds was announced in 2011 as part of the then chancellor George Osborne's ambition to create a northern economic "powerhouse".
The government said it would deliver more passenger capacity and shorten journey times.
However, the electrification was controversially paused in 2015 when a review into its costs and plans was carried out.
Speaking about this latest development, Ms Maskell said: "This is a slap in the face for the commuters and businesses in the North, including those in my constituency of York Central.
"Just six weeks ago the Tories promised the electrification of the TransPennine route as an integral part of the government's 'Northern Powerhouse'."
In an open letter to Mr Grayling, Greater Manchester mayor Andy Burnham said the north had "put up with second-class transport for too long".
He said the possible changes "would represent a major broken promise... and the derailment of the Northern Powerhouse".
Mr Grayling's announcement comes days after the government scrapped the planned electrification of three railway lines.
They included the routes between Cardiff and Swansea; between Windermere and Oxenholme in the Lake District; and between Kettering, Nottingham and Sheffield.
A Department for Transport spokesman said: "We are investing around Â£40 billion in our network as part of the biggest rail modernisation programme for over a century to provide faster journeys and more comfortable trains.
"This includes delivering improved journeys for passengers right across the North."
Some 20 people, including senior officials, have been killed in an attack on a hotel in the Somali capital, witnesses have told the BBC.
[NEXT_CONCEPT]
The railway route between Liverpool and Newcastle may not be fully electrified despite a promise by the previous government.