It was the deadliest attack in the Horn of Africa country since twin car bombs detonated near a busy market intersection in October 2022, killing at least 100 people and wounding 300 others.
There was no immediate claim of responsibility by the al Qaeda-linked al-Shabab, which has claimed similar attacks in the past, including the car bomb attack in 2022.
Police spokesperson Abdifatah Aden confirmed at least 32 people had died in Friday evening's explosion at a beach restaurant.
Somali state media has blamed the attack on the militant Islamist group al-Shabab. (EPA PHOTO)
Aden said one of the attackers had also blown himself up while three others had been killed by security forces.
One attacker was captured alive and one soldier was killed during the assault.
State news agency SONNA had earlier said five al-Shabab attackers had been killed by security forces while a sixth had blown himself up during the assault.
Hassan Farah, a survivor, described the shock as the explosion shattered a peaceful evening.
"I was in the restaurant sipping coffee and having a good chat with friends when I saw a big man running - in a second there was something like lightning and a huge blast," he told Reuters.
"We were covered with smoke.
"Inside and outside the restaurant many people were lying on the floor while others were bleeding and crying."
Videos posted on social media platform X showed bodies lying on the beach in the dark and people running to safety.
Al-Shabab controlled a vast area of Somalia but has been pushed back in government counteroffensives since 2022.
However, the militants remain capable of launching significant attacks on government, commercial, and military targets.
"The fact that the terrorist attack coincides with this night when the beach is the most congested shows the hostility of the terrorists to the Somali people," former prime minister Hassan Ali Khaire said on his X account.
With AP