The attack started on Wednesday evening as Muslims were breaking their daily fast during Ramadan.
A Syrian chef at the Pizza House restaurant, a modern venue popular with young Somalis, was among the victims.
Militants from the al-Shabab group held hostages during a shoot-out with police, which has now ended.
All five attackers are said to have been killed.
The al-Qaeda affiliated group admitted carrying out the attack.
The attack began at around 20:00 local time (17:00 GMT), when a car rigged with explosives hit the Posh Treats restaurant and night club - the only venue in Mogadishu with a disco.
Gunmen then entered the Pizza House restaurant on the opposite side of the road, seizing hostages.
BBC Somali service reporter Mohammud Ali said police stormed the building in the early hours of Thursday. Residents reported hearing gunshots throughout the night. The situation is now calm.
There are unconfirmed reports that they had been wearing police uniforms.
Troops from the African Union forced al-Shabab out of Mogadishu in 2011, but much of the country is still under control of the militants.
The militant group has launched a series of deadly attacks on Mogadishu and other government-held towns in recent months.
Most of the militant group's violent acts are "hit and run" style attacks.
This is the first major attack since the Muslim holy month of Ramadan began three weeks ago - a time when al-Shabab usually increases the frequency of its attacks.
In recent weeks, the security forces have been carrying out disarmament operations in the capital.
Somali President Mohamed Abdullahi Farmajo recently vowed to destroy al-Shabab within two years.