Government forces fought a gun battle with the the attackers, who were identified as members of the al Shabaab terror group. The country's security minister said the alleged commander of the attack was captured alive by security forces. The commander was not named.
"This is a barbaric act and we condemn this act," government spokesman Abdisalam Aato said. "Al Shabaab is trying to disrupt the peace and Somalis will not stand for it. We will not be intimidated."
The attack started about 7:30 p.m. local time Thursday when a car rammed the gate of the Liido Seafood Restaurant overlooking a Mogadishu beach, said Col. Abdulkadir Mohammed, a senior police officer.
After the blast, militants entered the adjoining hotel -- at least some of them by boat -- Mohammed and a Western source in Mogadishu told CNN. The hotel was crowded with graduation and wedding ceremonies, the National Intelligence & Security Agency (NISA) of Somalia said in a tweet.
"Thursday night in Mogadishu is like Friday night in other countries," Aato said. "It's very busy. People have their weddings; they go out to eat with their families."
Al Shabaab claimed responsibility for the attack on its mouthpiece radio station, reporting that its fighters armed with AK-47 rifles and wearing suicide vests had invaded the hotel.
Al Shabaab, an al Qaeda-linked militant organization, has carried out similar attacks targeting civilian areas in the past.
The group's aim is to turn Somalia into a fundamentalist Islamic state, according to the Council on Foreign Relations, but it has seemingly gone beyond that goal -- and beyond Somalia -- with a host of horrific attacks, such as last year's massacre at Kenya's Garissa University College
and a 2013 siege of Nairobi's upscale Westgate Mall
Last week, al Shabaab militants staged a deadly attack on an African Union base in southwestern Somalia.
And last fall, the Islamist militant group claimed responsibility for blasts and gunfire at Mogadishu's popular Sahafi Hotel
. At least 15 people were killed in that attack, officials said.
"This attack further demonstrates the vile nature of al Shabaab, whose sole purpose is to spread terror and destabilize Somalia," the African Union mission tweeted. "Our resolve can only be rejuvenated, to fight on until Somalia is freed of all elements of terror."
In a Twitter post, Prime Minister Omar Abdirashid Ali Sharmarke wrote, "I unreservedly condemn the barbaric attack @ Liido. My thoughts and prayers are with the victims."