At least 14 people were killed when gunmen stormed a hotel in Somalia's capital and took an unknown number of hotel guests hostage, police and medical workers said Saturday.

Security forces have ended an hours-long assault that began with an explosives-laden vehicle blowing up at the hotel gate.

Islamic extremist group al-Shabaab claimed responsibility for the latest in a series of hotel assaults in Mogadishu.

Police said the attack on the Nasa-Hablod hotel began when a suicide bomber detonated an explosives-laden vehicle at its gate. Gunmen fought their way inside and a witness said they began shooting randomly at hotel guests.

Siege is over

"We have finally ended the siege. The last remaining militants were killed on the top floor," police Capt. Mohamed Hussein said after security forces pursued the gunmen who had retreated to upper floors of the Nasa-Hablod hotel.

At least four gunmen were involved in the attack and they set up sniper posts on the roof and threw grenades in their battle with security forces.

"We have so far confirmed the deaths of 14 people. Some of them died in the hospitals," Hussein said. The deaths included women who were selling khat, a stimulant leaf popular with Somali men, outside the hotel, he said.

People flee from the scene of a car bomb attack in Mogadishu. (Mohamed Abdiwahab/AFP/Getty Images)

Hussein said security forces killed all of the attackers.

He also said he saw four bodies, thought to be civilians, lying outside the hotel.

It was not known how many guests were inside.

Guests wounded in crossfire

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 that he transported 11 people injured in the attack to hospitals.

"Most of them were wounded in crossfire," he said.

The Somalia-based, al-Qaeda-linked al-Shabaab 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-Shabaab 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.

Security forces gather outside the Nasa-Hablod hotel, where gunmen took hostages. A witness said the attackers began shooting randomly at hotel guests after forcing their way into the building. (Reuters)

African Union to withdraw some troops

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-Shabaab 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 per cent. 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.