The al-Qaida-linked terror group claimed victory and said the attack was a revenge for the latest civilians killed in airstrike by Somali and USA forces.
Abdiasis Abu Musab, al-Shabaab's military operations spokesman, told media outlets they had killed 17 Somali soldiers and stolen seven military vehicles.
The militants used guns and auto bombs to take control of the Somali National Army military camp and a nearby town, Barire, 50 km southwest of Mogadishu, in an early-morning attack.
Abdifatah Omar Hallane, Mogadishu municipality's spokesman, told reporters in a news conference that the bomb-laden vehicle was a luxury auto parked near the restaurant.
Al-Shabaab militants attacked a military base near capital Mogadishu Friday morning killing at least 12 Somali soldiers, a security official said.More news: Ryanair Extends Flight Cancellations
A Somali military officer put the number of dead at 15; Shabaab said 21 were killed.
Bariire has become a center of attacks in the Lower Shabelle region after Al shabaab militants were driven out of the town in August, 2017 by Somali government troops backed by AU and United States forces.
Capt Mohamed Hussein said the blast late on Thursday was at a vehicle parked outside a restaurant in Mogadishu's Hamarweyne district and killed mostly civilians.
Despite losing most of its key strongholds to the Somali army and the regional forces of the African Union, al-Shabab has ramped up its campaign against the Somali government in recent months, largely targeting army bases across the country.
"What happened was a auto bomb hit a mini-bus". It has been carrying out militancy since 2006.