At least five people were killed in an hours-long Al-Shabaab attack on a Mogadishu hotel which ended around midnight on Sunday, Somali police said.

The Al-Qaeda-linked militants detonated a car bomb at the entrance to the Hotel Afrik at a busy junction near the airport before gunmen stormed the hotel, exchanging fire with security personnel.

Somali police spokesman Sadik Dudishe told a press conference that four attackers had also died.

"Among the dead are five civilians and the gunmen -- three of them shot and another who detonated himself. The death toll can be higher and some of the wounded people may succumb."

He said 10 people had been injured.

The information ministry said in a statement that one of the victims was well known retired military official General Mohamed Nur Galal.

Ali Ato, who went to the hotel to recover the dead body of a colleague who was killed during the raid, described the scene.

"I have never witnessed such a level of devastation. We found the dead body of my colleague in front of the room where he stayed but I don't know if they shot him or he was killed in a grenade explosion," Ato told AFP.

Al-Shabaab claimed responsibility for the attack in a brief statement, saying: "The mujahidin stormed in an ongoing operation inside Hotel Afrik where members of the apostate team are stationed."

The hotel is frequented by Somali officials, members of the security forces and community leaders.

Al-Shabaab has been waging a violent insurgency across the Horn of Africa country seeking to unseat the internationally backed government in Mogadishu.

They were driven out of Mogadishu by government forces backed by African Union peacekeepers in 2011.

But the group still controls swathes of territory outside the cities, from where they launch attacks against government and civilian targets. It has also carried out deadly attacks in neighbouring Kenya.

Somalia was scheduled to hold indirect parliamentary and presidential elections before February 8, but the process has been derailed by political disagreements between the central government in Mogadishu and its federal states.