Al Shabaab militants have attacked the Somali presidential palace compound, killing at least 11 people.

The attack saw a car bomb explode at the gate and militants engage in a gun battle with African peacekeepers.

Somali President Hassan Sheikh Mohamud was unharmed in the assault on the heavily-fortified compound known as Villa Somalia.

The Al-Qaeda-linked group claimed responsibility.

There were conflicting reports about what happened.

Somalia National Security Minister said all nine attackers were killed in the ensuing battle with African peacekeepers.

"Nine al Shabaab fighters gained entry to the presidential palace with the aim of attacking, but all of them were killed on the spot," said Security Minister Abdikarim Hussein Guled.

A government official who declined to be named said the militants reached a mosque in the centre of the compound where the president usually prays on Fridays.

The chief of staff of the office of the prime minister and a former chief of intelligence were killed, along with six militants, he said.

The president was not at the mosque at the time of the attack.

"We call on all Somali people to stay calm because we are ready to protect our officials and our people from evildoers," Mr Guled said.

In the past few weeks, the Somali capital of Mogadishu has been hit by a series of suicide bomb attacks claimed by al Shabaab, who were pushed out of the city in mid-2011 but have continued to wage a sustained guerrilla campaign.