"The operation is over now and the gunmen were killed by the security forces," said Mohamed Ahmed Arab, spokesman for Somalia's security ministry.
"They have attacked business places and killed innocent civilians: 18 civilians were killed, including a Syrian national, and more than 10 others were wounded," he said.
The attack began at around 8pm (1700GMT) on Wednesday evening with a suicide car bombing at the Posh Treats restaurant and club, after which gunmen stormed inside the nearby Pizza House restaurant.
The gunmen spent the night roaming the restaurant killing those they found trapped before they were eventually killed by the security forces.
Get the latest election news, live updates and election schedule for Lok Sabha Elections 2019 on ndtv.com/elections. Like us on Facebook or follow us on Twitter and Instagram for updates from each of the 543 parliamentary seats for the 2019 Indian general elections.