The militants attacked from several directions, and security forces killed at least six after battling them until nearly dawn on Friday.
The Shabab, which have vowed to turn Somalia into a puritanical Islamic state, claimed responsibility for the attack. The group killed scores of Kenyan soldiers last week and seems to be trying to reassert itself.
Witnesses said that the attack started when Shabab fighters emerged from the beach and began firing at patrons of the Lido beachfront restaurant. People fled in the other direction, but they were killed and wounded by a bomb-laden car that exploded at the restaurant’s gates.
The militants took over the restaurant, killing hostages as security forces struggled to get in. Witnesses said that many people were hiding in the bathrooms — especially the women’s bathroom — as the militants stormed from room to room.
Somali soldiers eventually broke through a wall, and customers wiggled out to safety. Among the confirmed dead were a pregnant mother and a small child.
The attack resembled recent militant assaults on hotels in Burkina Fasoand Mali, although the targets in those cases were hotels and restaurants popular with foreigners. Mogadishu has a very small number of expatriates and overseas visitors, and no foreigners were reported to have been killed or wounded in the beachfront attack.
The few that are here rarely venture out at night. Somalia has been steeped in civil war for more than 20 years, though Mogadishu has recently enjoyed a surge of investment and development.
The Shabab remain a threat, however, relentlessly attacking several of the city’s most affluent restaurants and hotels, including those along the white-sand beaches that are popular with families.
Analysts say the Shabab are rebuilding themselves with weapons looted from recent attacks on African Union peacekeepers. Last week, the Shabab devastated a Kenyan base, killing as many as 100 Kenyan soldiers — possibly even more — and making off with all their equipment, including artillery guns, sophisticated communications equipment, six-foot-high stacks of ammunition, uniforms, flak jackets and several American-made Humvees.
Kenya’s leaders have still not disclosed the number of casualties, despite calls from the public urging the government to provide details about exactly what had happened.