AT LEAST 35 people have been killed and dozens more wounded in a car bomb attack followed by an invasion of a hotel in the Somalian capital of Mogadishu.

Witnesses to the apparent terrorist attack on Saturday said that the gunmen took an undetermined number of hostages inside the hotel, but police told EFE that security forces had retaken control of the building after a four-hour siege.

The car-bomb blast came about 4.30pm local time and produced a large column of smoke over the Nasa-Hablod Hotel in Mogadishu, frequented by politicians, and sporadic gunfire continued to be heard in the hours after the explosion.

Local police said that security forces had mounted an operation to free the hostages in which all the terrorists - reported to number four - were killed.

“We have finally ended the siege. The last remaining militants were killed on the top floor,” police Captain Mohamed Hussein said after security forces pursued the gunmen who had retreated to upper floors of the Nasa-Hablod hotel, setting up sniper posts on the roof and throwing grenades.

Initially, nine people, including several hotel security guards, had been reported killed and later in the day this figure was raised to 18, but police officer Abdullahi Gardhere, who was on the scene, confirmed to EFE that the fatalities numbered 35.

He also said that more than 30 people had been wounded and are being attended to by medical personnel at the attack site and in local hospitals.

The al-Shabaab jihadist group claimed responsibility for the attack.

The affiliate of al-Qaeda in Somalia in recent months has attacked numerous hotels and restaurants in the capital, according to the Shabelle News website.

A witness, Ali Mohamud, said the attackers randomly shot at guests. “They were shooting at everyone they could see. I escaped through the back door,” he said.

Yusuf Ali, an ambulance driver, told The Associated Press he evacuated 11 people injured in the attack to hospitals.

“Most of them were wounded in crossfire,” he said.

The Somalia-based, al-Qaeda-linked al-Shabab has been waging a deadly insurgency across large parts of Somalia and often employs suicide car bomb attacks to penetrate heavily fortified targets in Mogadishu and elsewhere.

In early June, an overnight siege by extremist gunmen at another hotel in the capital killed least 15 people, including two members of parliament. Al-Shabab claimed responsibility for that attack. The latest attack comes during the Muslim holy month of Ramadan, during which extremists often step up attacks in this volatile East African country.

“They came shouting ‘Allahu Akbar’ and fired bullets on every side,” said a hotel staffer who escaped through the back door. He declined to be identified for fear of reprisal.

“They are devils who merely care for death and blood,” the staffer said.

The assaults in the seaside capital have highlighted the challenges facing the Somali government and African Union forces that are struggling to secure the country. An attack on another Mogadishu hotel and public garden in February killed at least nine civilians. A car bomb outside a restaurant in the capital in April killed at least five.

The al-Shabab insurgents have been ousted from most of Somalia’s cities but continue to carry out bombings and suicide attacks. The African Union force faces shrinking resources after the European Union recently cut its funding to the AU mission in Somalia by 20 percent. Citing that cut, Uganda’s military chief said Friday his country plans to withdraw its more than 6,000 troops from the AU force in Somalia by December 2017. The Ugandans are the largest troop contingent.