At least 17 people were killed in a night-long siege of a popular Mogadishu restaurant by al-Shabab Islamic extremists which was ended on Thursday morning by security forces.
Survivors described harrowing scenes in which the attackers hunted patrons of the popular Pizza House in the capital. The injured were taken to hospital by ambulance.
Al-Shabab claimed responsibility while the restaurant was under siege.
Soldiers surrounded the building and used guns mounted on the backs of vehicles to neutralise the militants. Troops entered the ground floor while the insurgent snipers held positions upstairs.
All five attackers were killed and after dawn the soldiers secured the building, said senior Somali police office Captain Mohamed Hussein. The troops' efforts to take control of the restaurant were slowed by the darkness, forcing them to wait until morning, he added.
Survivors said they hid under tables and curtains as the gunmen continued firing in the restaurant and hunted for patrons. The attackers moved from room to room, looking for people, said one.
"I never thought I would have the chance to see the sun again. They were killing people on sight," university student Saida Hussein told the Associated Press. She said she survived the attack by hiding behind a large table downstairs.
Another survivor, Aden Karie, was wounded by an attacker who spotted him moving behind a curtain in the dark room.
"He shot at me twice and one bullet struck me on the leg," he said as he was taken to a waiting ambulance.
The roofs were blown off the restaurant and nearby buildings by the powerful blasts.
The bodies of five girls thought to have been killed by the militants were found in the restaurant, said police. Also inside the building, the body of a Syrian man who worked as a chef lay near the rubble of a blood-spattered and bullet-marked wall.
The attack began on Wednesday evening when a car bomb exploded at the gate to the restaurant and then gunmen posing as military forces stormed into the establishment.
An ambulance driver with the Amin Ambulance service, Khalif Dahir, said that early on Thursday they had transported 17 bodies and 26 wounded people. Most of the victims were young men who had been entering the Pizza House when the vehicle exploded, said Capt Hussein.
The gunmen "were dressed in military uniforms. They forced those fleeing the site to go inside" the restaurant, witness Nur Yasin said.
Wednesday night's blast largely destroyed the restaurant's facade and sparked a fire.
While al-Shabab claimed to have attacked the neighbouring Posh Treats restaurant, which is frequented by the city's elite and was damaged in the blast, security officials said the Pizza House was targeted instead.
Security forces rescued Asian, Ethiopian, Kenyan and other workers at Posh Treats as the attack continued, Capt Hussein said.
The Somalia-based al-Shabab often targets high-profile areas of Mogadishu, including hotels, military checkpoints and areas near the presidential palace. It has vowed to step up attacks after the recently elected government launched a new military offensive against it.
Al-Shabab last year became the deadliest Islamic extremist group in Africa, with more than 4,200 people killed in 2016, according to the Washington-based Africa Centre for Strategic Studies.
The extremist group also faces a new military push from the United States after President Donald Trump approved expanded operations, including air strikes, against al-Shabab. On Sunday, the US military in Africa said it carried out an air strike in southern Somalia which killed eight Islamic extremists at a rebel command and logistics camp.
Somalia President Mohamed Abdullahi Mohamed confirmed that air strike and said such attacks would disrupt the group's ability to carry out new attacks.
With a new federal government established, pressure is growing on Somalia's military to assume full responsibility for the country's security. The 22,000-strong African Union multinational force, Amisom, which has been supporting the fragile central government, plans to start withdrawing in 2018 and leave by the end of 2020.
Also on Wednesday, the UN Security Council unanimously adopted a resolution extending the United Nations political mission in the Horn of Africa country, which is trying to rebuild after more than two decades as a failed state, until March 31 2018. The resolution recognised that "this is a critical moment for Somalia".