MOGADISHU, Somalia — Militants began an assault in the capital, Mogadishu, on Wednesday evening with a car bombing at the gates of a hotel popular with foreigners, and continued with gunfire at a nearby restaurant.
The Associated Press put the death toll at 31, citing local officials and the emergency services, an increase from an earlier estimate of 18 people. Special forces troops rescued more than 50 hostages, state news outlets reported.
The attack occurred less than a week after militants from the Shabab extremist group killed dozens of people — both soldiers and civilians, including children — when they stormed a military base in northeastern Somalia.
On their website, the Shabab took responsibility for the violence on Wednesday, which started at the Posh Hotel in central Mogadishu. After a car bomb exploded at the hotel’s gates, gunmen fanned out to the Pizza House restaurant.
Many people, including visitors from Ethiopia and Kenya, had been enjoying a night out.
“I saw several people lying on the ground,” said Yusuf Warsame, a freelance photojournalist who went to the scene. “I personally counted the dead bodies of six people, including a young woman.”
It was not known how many people were being held captive early Thursday, but the Shabab, who have links to Al Qaeda, are known for killing hostages, not holding them for ransom.
The Shabab have been fighting the United Nations-backed government in Somalia for years, seeking to impose their strict interpretation of Islam. They have also been behind attacks in Uganda and Kenya, including the Westgate Mall siege in Nairobi in 2013. Recently, they have carried out a series of attacks in Kenya, killing dozens.
Although the group has suffered defeats, including the deaths of leaders and the loss of territory, the Shabab’s ability to inflict harm remains undiminished. Devastating attacks on hotels have been one of their trademarks.
Last Sunday, the United States military carried out a drone strike in southern Somalia against the Shabab, the first since President Trump relaxed some rules for preventing civilian casualties when the Pentagon carries out counterterrorism strikes.
The strike, which the military said had targeted the command and logistics portion of a Shabab camp, came two and a half months after Mr. Trump cleared the way for offensive strikes in Somalia, a chaotic nation in the Horn of Africa, without a specific self-defense rationale.