A suicide bomber has detonated an explosives-laden truck near the gate of Somalia's presidential palace in Mogadishu, killing at least 12 people, police said.

The bomb exploded during a morning traffic jam in the capital, said Captain Mohamed Hussein, a senior police officer.

The blast damaged nearby hotels often frequented by government officials and business executives, he said, and some cabinet ministers at the SYL hotel were among 31 injured.

The explosion was heard across Mogadishu, and smoke was seen billowing over the presidential compound.

Somalia's Islamic extremist group al-Shabab has claimed the blast, according to the rebels' Andalus radio station.

The injured were taken to Mogadishu's Madina Hospital, said Dr Mohamed Yusuf, the hospital's director.

The massive blast left a trail of destruction across the hilltop presidential complex and nearby buildings. The bombing tore into blast walls protecting hotels and blew off the roofs of houses.

"Security forces tried to stop the bomber who used back roads before he sped through checkpoints near the presidential palace and detonated the bomb," said police spokesman Colonel Ali Nur. "He reached near the gate of the state house with flat tyres."

While al-Shabab has been ousted from most of Somalia's cities, it continues to carry out bombings and suicide attacks, notably in the capital.

In late July, two al-Shabab suicide bombers detonated explosives-laden cars outside the office of the UN's mine-clearing agency and an army checkpoint near the African Union's main base in Mogadishu, killing 13.

In June, gunmen stormed the Nasa-Hablod hotel, killing at least 14. Two weeks before that, more gunmen killed 15, including two members of parliament, at the Ambassador hotel.