Somali security forces said they had rescued 106 people who were trapped inside a hotel that had been raided by militants on Friday night.
Twenty-one people died and 117 were injured in the 30-hour ordeal, the Health Ministry said. Officials say the fight to retake the hotel is over.
The assailants used explosives to break into Mogadishu’s Hayat Hotel before violently taking control.
The Islamic militant group al-Shabab claimed responsibility for the attack.
Police Commander Abdi Hassan Mohammed Hijra told reporters about the numbers rescued, which he said included women and children, but did not give a death toll.
The hotel was largely destroyed after intense fighting between the militants and security forces overnight on Friday and Saturday, with videos showing explosions and smoke billowing from the building’s roof.
“Security forces have ended the siege now and the snipers are dead, we haven’t received any shots from the building in the last hour,” an unnamed official told the AFP news agency.
“It was terrible, really terrifying to live next to the shooting, the explosions. It was one of the most horrible things I’ve seen in Mogadishu,” Abdisalam Guled, former deputy director of Somalia’s national intelligence agency, told the BBC. .
Relatives of those who would have been at the hotel when the attack took place are now waiting to find out what happened to them.
“My brother was inside the hotel the last time we heard from him, but his phone is off now and we don’t know what to expect,” businessman Muktar Adan told AFP.
A police officer told Reuters that two car bombs were used to gain access to the hotel on Friday night – targeting its front barrier and gate.
After the initial attack, an al-Shabab-affiliated website said a group of militants was “carrying out random shootings” after “forcibly breaking into” the hotel – described as a popular place for federal government officials to meet.
Security forces struggled to gain access to the hotel’s upper floors for hours as gunmen, who were holding an unknown number of people hostage, reportedly bombed the stairs necessary for access.
The director of Mogadishu’s main trauma hospital told AFP the unit was treating at least 40 people injured in the attack on the hotel and another mortar attack in another area of the capital.
Al-Qaida’s affiliate, Al-Shabab is involved in a long-standing conflict with the federal government.
The group controls much of southern and central Somalia, but has managed to extend its influence into areas controlled by the Mogadishu-based government.
In recent weeks, fighters affiliated with the group have also attacked targets along the Somali-Ethiopia border, raising concerns about a possible new al-Shabab strategy.
The attack on Friday marks the first in the capital by the group since Somalia’s new president, Hassan Sheikh Mohamud, was elected in May.
Hotels and restaurants have been frequent targets, but Mogadishu saw its deadliest attack in October 2017, when more than 500 people were killed when a truck full of explosives detonated at one of the city’s busiest intersections.
No group has claimed to be behind the attack, although correspondents say all indications are that al-Shabab was responsible.