The six attackers -- one suicide bomber and five gunmen -- "attacked business places and killed innocent civilians:
"The operation is over now and the gunmen were killed by the security forces," said Mohamed Ahmed Arab, spokesman for Somalia's security ministry.
He said the six attackers -- one suicide bomber and five gunmen -- "attacked business places and killed innocent civilians: 18 civilians were killed, including a Syrian national, and more than 10 others were wounded."
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 Syrian national is believed to have been a chef at Pizza House.
Both venues are popular with affluent, young and diaspora Somalis and were busy as customers broke the Ramadan fast.
Islamist attacks often increase in tempo during the holy month but Wednesday's was the first major assault by the Shabaab this Ramadan.
The gunmen spent the night roaming the restaurant killing those they found trapped before they were eventually killed by security forces whose operation had been slowed by the darkness.
Survivors and witnesses described chaos after the bomb went off.
"I was about to have dinner when the blast threw me to the ground," said Abdikarim Ahmed, a customer at Posh Treats. "I rushed to the nearby exit and went out. I could see the chaos caused by the blast and shrapnel everywhere."
Abdukadir Mohamed, who was close by, said it was the loudest blast he had ever heard in years living in Mogadishu. "It was very close. I could see the huge fire it caused, the dust, destruction, everything. Both Pizza House and Posh Treats were on fire. The whole area looked like a different place," he said.
Others spoke of finding dead relatives and friends. "One of my neighbours was among the dead, a young innocent girl. When I saw her body this morning I could not stop my tears," said Abdiwahid Ali.
Worshippers in a neighbouring mosque were thrown to the ground and felt the walls shake and windows shatter.
"You cannot recognise this area," said Hawa Ahmed, a local resident and a regular at Pizza House, who had opted not to visit last night.
"Where there were two beautiful restaurants, this morning there is complete devastation and death, blood and body parts everywhere."
The Shabaab, an al-Qaeda aligned militant group that carries out regular suicide bombings and raids in the capital against civilian, government and military targets, claimed responsibility for the attack, saying it had targeted a "nightclub" frequented by "foreigners, government and intelligence officials".
Pizza House, where most of the civilian victims were killed, is a popular outdoor spot for iftar, the breaking of the Ramadan fast.
Posh Treats in a converted villa across the road is a liberal hangout with shisha pipes and a disco, a rarity in Mogadishu.
The austere Shabaab group, which wants to impose a Taliban-style rule on Somalia, has been fighting for the last decade to overthrow successive internationally-backed governments in Mogadishu and has also launched attacks in Kenya and Uganda, both contributors to a 22,000-strong African Union force in the country.
Although pushed out of the capital in 2011 the group still controls parts of the countryside, where a drought threatens to tip into famine this year.