Two large explosions in Somalia's capital city Mogadishu have killed at least 18 people and injured dozens.

One attack took place at the gates of the presidential palace, while a second hit near offices of the national intelligence agency.

Officials say five of the attackers were shot and killed.

The Islamist militant group al-Shabab, which opposes Somalia's UN-backed government, says it carried out the attacks.

The attack on the palace began when militants failed to stop at a checkpoint, resulting in an exchange of gunfire, state-owned media say.

Then a parked car blew up near a hotel, security officials say.

However, al-Shabab said it had targeted "a national security forces' base".

A spokesman for the group said both car bombs had involved suicide bombers.

The group said the attacks had killed 15 soldiers, without providing any evidence.

A police spokesman told Reuters news agency: "There were many military soldiers who guarded the street adjacent to the palace."

The attacks came a day after the security minister warned of a possible car bomb attack in Mogadishu, Somalia's Radio Simba reports.

They are the latest in a series of high-profile incidents attributed to al-Shabab, which once controlled Mogadishu before being forced out by African Union troops in 2011.

In October last year, more than 500 people were killed by a truck bomb in the city.

Officials blamed al-Shabab for the bombing but the group never said it was behind the attack.