NAIROBI, Kenya — A nearly daylong siege in the heart of Somalia’s capital ended with all of the al-Shabab extremist attackers killed, police said Friday, as the death toll was at 24 and expected to climb.

Capt. Mohamed Hussein said that an operation to clear the besieged buildings had begun. Two of the dead were soldiers, he said.

The overnight attack began with a pair of car bombs exploding in a popular area of Mogadishu where Somalis were relaxing at restaurants and hotels Thursday. One went off near the home of appeals court chief Judge Abshir Omar, and security forces fought off gunmen who tried to force their way inside, Hussein said.

“We heard a huge blast, a devastating blast that affected all the buildings,” said Mohamed Ibrahim Mo’alim, the secretary general of the national union of Somali journalists.

At least four gunmen then opened fire at nearby buildings and businesses, sparking clashes with hotel guards, he said. Dozens of cars caught fire along busy Maka Almukarramah Road.

The extremists then holed up inside buildings, exchanging gunfire with security forces who worked well into Friday to free trapped civilians. More than 35 people were rescued, Prime Minister Hassan Ali Khaire said Friday after visiting the area of shattered buildings.

The al-Qaida-linked al-Shabab, Africa’s deadliest Islamic extremist group, claimed responsibility for the attack and said its target had been the nearby Maka Almukarramah hotel, which is patronized by government officials. The extremist group has targeted it multiple times, killing scores of people.

Police said the death toll could rise. Doctors at Erdogan Hospital in Mogadishu said they had received 55 wounded people, with three succumbing to injuries. Many were in critical condition and 15 had undergone surgeries, said Dr. Ismail Yamas, the hospital manager.

The style of the attack echoed previous ones by al-Shabab in Mogadishu as well as the attack in January at a luxury hotel complex in the capital of neighboring Kenya that killed 21 people.

The United Nations mission in Somalia and others in the international community quickly condemned the attack, one of the worst in Mogadishu in months.

It came after the U.S. military carried out a number of deadly airstrikes in recent days against al-Shabab, considered the deadliest Islamic extremist group in Africa. Al-Shabab opposes Somalia’s federal government and wants to impose sharia law.

The U.S. has dramatically increased such airstrikes since President Donald Trump took office. The U.S. military command for the African continent reported carrying out 50 strikes in Somalia in 2018.

The U.S. says it acts in coordination with Somalia’s government, whose military is expected to take over primary responsibility for the country’s security over the next few years.