"The last terrorist gunman was killed after the security forces destroyed a room in which he was taking cover and the siege is over now," Ismail Muktar, the commissioner for Hamar Jajab district, told reporters.
"The security forces are clearing the area."
The attack began on Thursday evening at around 1800 GMT, when a Shabaab militant in a car blew himself up, causing a huge blast that ripped the front off a major hotel and left several cars in flames on the busy street.
Other fighters then stormed inside a building housing a restaurant, where they were quickly surrounded by police.
Sporadic shooting continued throughout Thursday night and into Friday.
Gunmen battle police in Somali capital after bombing
Medics pulled five bodies from the wreckage immediately after the explosion, but the recovery of more bodies was blocked for hours by the ensuing fighting.
"Those killed include children. The Shebab assailants, whom we saw, were only two," said former Somali MP Abdi Barre Jibril.
By Friday afternoon, officials said the death toll had climbed significantly.
"We have recovered 14 more dead bodies from under the rubble of collapsed buildings, bringing the total number of dead to 19," said Aamin Ambulance director Abdikadir Abdirahman.
At least 112 people were admitted to the city's three main hospitals, hospital sources said.
Heavy explosions could be heard coming from the building on Friday afternoon as elite soldiers appeared to move in to storm Shabaab positions.
The attack is the latest in a long line of bombing and assaults claimed by the al Qaeda-linked group.
Death toll from Somali bombing rises to 20
The organisation announced that fighters waged a 'martyrdom-seeking' and commando operation against what it described as a "luxury hotel inhabited by government officials and security service officers."
The explosion which began the assault was so powerful that it tossed several vehicles into the air that then burst into flames. Witnesses said the bombing took place in the early evening, when the street was filled with people relaxing after a day's work.
"The whole area was in flames," said Abdisamed Mohamed, a witness. "There was gunfire too."
The head of Somalia's journalist union, Mohamed Ibrahim Moalimuu, who survived the attack, described the devastation.
"I was the first one who came out of the hotel when the explosion took place and I saw many vehicles burning at the scene," he said.
The Shabaab emerged from Islamic Courts that once controlled central and southern Somalia and are variously estimated to number between 5,000 and 9,000 men.
In 2010 the Shabaab declared their allegiance to al Qaeda.
The following year, the group were chased out of Mogadishu by the 22,000-strong African Union peace-enforcement mission, AMISOM.
They have since lost many of their strongholds but retain control of large rural swathes of the country and continue to wage a guerrilla war, frequently hitting Mogadishu.
In October 2017 a truck bombing in a busy neighbourhood of the capital killed over 500 people, the deadliest attack in Somalia to date.
The Shabaab have also carried out a string of attacks in Kenya since 2011.
The deadliest of these took place on April 2, 2015 when 148 people were killed at Garissa University in northeastern Kenya.
In 2013, a Shabaab raid on Nairobi's Westgate shopping mall left 67 dead, a siege that unfolded over four days. And in January this year, 14 people were killed in a Shabaab-claimed attack on a luxury hotel complex in Nairobi.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ