"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 (17.00GMT) on Wednesday evening with a suicide car bombing at the Post 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.