Two car bombs exploded about an hour apart early on Thursday evening. In between, gunmen approached from the beach, firing on diners.
A siege followed, lasting eight hours, but has now ended, the ministry said.
Al-Shabab said it was behind the attack. The group has carried out frequent assaults on the capital.
Somali Prime Minister, Omar Abdirashid Ali Sharmarke, condemned the attack as "barbaric".
There are varying reports about how the attack started but it appears that as the first car bomb went off, at around 19:30 local time (16:30 GMT) on Thursday, the gunmen stormed the area.
They are reported to have burst into one of the restaurants and took hostages.
"They randomly fired at the people sitting near the beach before entering the restaurant,'' witness Ahmed Nur told Associated Press. Read more on bbc.