Militants stormed the presidential palace in the Somali capital, Mogadishu, on Tuesday, police said, sparking heavy gunfire as government troops and guards tried to repel them.

Reuters reported that the country's interior minister said five of the militants, who belonged to the al-Qaeda-linked group al-Shabab, were killed in the attack.

Police officer Mohamed Abdi said the attack started when a car bomb exploded outside the presidential complex. Gunmen then entered the palace.

Somalia's president, Hassan Sheikh Mohamud, was not inside the palace when the attack happened, but the prime minister and the speaker of parliament were inside the complex, said Capt. Mohamed Hussein, a senior police official.

Hussein said that once inside, the militants split up into different groups and tried to take control of different parts of the palace.

"The operation is still under way," he said, referring to efforts to fight the militants.

A spokesman for the al-Qaeda-linked group Al-Shabab confirmed to Reuters its members were involved in the attack.

"We have entered the so-called presidential palace. We have now captured some parts of the palace and fighting is still going on," Sheikh Abdiasis Abu Musab, al-Shabab's military operations spokesman, told Reuters.

No more details were immediately available, but the attack is widely believed to have been carried out by the Islamic extremist group al-Shabab, which has vowed to step up attacks during the Muslim holy month of Ramadan.

Al-Shabab had previously staged many attempts to enter the heavily-guarded presidential palace, but this is the first time they have succeeded.

With files from Reuters