The attackers entered the Ambassador Hotel on Maka al-Mukarama street after setting off a car bomb at the gates outside, witnesses said.
Somalia's state news agency said two MPs were killed in the blast, with another four rescued.
The al-Shabab militant group was quick to say it was behind the attack.
The BBC's Somali Service reporter Ibrahim Aden in Mogadishu says the explosion is one of the largest to hit the city and the scale of destruction is huge.
Somalia's state news agency Sonna said at least 50 people were hurt and that the death toll was likely to rise.
It named the dead MPs as Abdullahi Jama Kabaweyne and Mohamoud Mohamed Gure.
The head of the city's Amiin ambulance service has told the BBC the main Medina hospital is overcrowded.
"I was the first person to reach scene. The damage was enormous," Dr Abdulkadir Andirahman Haji Aden said.
"My brother and his son were among those injured. We are now in Medina hospital and it is overcrowded with wounded people. I have never seen something like this."
Al-Shabab, which is battling the UN-backed government, was driven from Mogadishu in 2011 but still remains a potent threat and frequently carries out attacks in the city.
The government, with the help of African Union forces, is fighting the al-Qaeda-linked group to regain control of the country.
Earlier on Wednesday, the government announced it had killed Mohamed Kuno, the al-Shabab militant who led the attack on Garissa University in Kenya in April 2015 that killed 148 people.
He was one of 16 al-Shabab militants - four of them senior leaders - killed in an overnight raid on their convoy in Kismayo, a port city in southern Somalia.
Gunmen have stormed a hotel in the centre of the Somali capital Mogadishu, with reports of at least 10 dead and 50 wounded.