Residents carry an injured man wounded during a complex car bomb attack targeting a Mogadishu hotel on January 25, 2017

Mogadishu (AFP) - Twenty-eight people were killed Wednesday when Al-Shabaab fighters attacked a popular Mogadishu hotel, setting off two car bombs and opening fire on security guards, according to the city's main ambulance service.

The attack, claimed by the Al-Qaeda-aligned Shabaab insurgents, began when a car loaded with explosives rammed the gate of the Dayah Hotel near the Somali parliament and state house.

Security sources said at least four gunmen then entered the compound and exchanged fire with security guards, but they were shot dead before reaching the main building where guests were staying. They were not counted among the 28 dead.

A second massive blast went off after ambulances and journalists had already rushed to the scene, leaving seven reporters with minor injuries, according to the National Union of Somali Journalists (NUSOJ).

They included an AFP photographer who suffered shrapnel wounds to his shoulder and leg, an Associated Press photographer and a reporter working with Al-Jazeera television.

"The number of casualties we have recorded today is 28 dead and 43 wounded. This is what we have confirmed with our teams but there were also other ambulances which carried some casualties (but) I don't know how many," said Dr Abukadir Abdirahman Adem, head of the ambulance service.

Somalia's Security Minister Abdirisak Omar Mohamed told reporters there were 10 people killed and 51 wounded in the attack.

"We commend the security guards of the hotel who fiercely fought the Shabaab attackers to defend the hotel," he said.

AFP images showed security forces and civilians milling about outside the devastated hotel -- its windows and doors blown out -- after the first explosion, when a second car exploded with a massive blast, sending thick plumes of smoke into the air and sending people fleeing.

Gunfire rang out from the hotel as civilians and rescue workers carried away the injured.

The Shabaab group claimed responsibility in a statement distributed on its Telegram messaging account.

"The mujahideen fighters have attacked a hotel and have managed to enter the hotel after detonating a car loaded with explosives," it said.

The Shabaab is fighting to overthrow the internationally-backed government of Somalia and regularly stages deadly attacks on state, military and civilian targets in the capital and elsewhere in the war-torn country.

- Election date set -

The attack -- the deadliest so far in Somalia in 2017 -- came shortly before the country's election commission announced that a long-awaited presidential vote would take place on February 8.

The date has been pushed back numerous times amid delays in a vote for lawmakers, who were finally sworn in in late December.

Somalia has not had an effective central government since the 1991 overthrow of president Siad Barre's military regime, which ushered in more than two decades of anarchy and conflict in a country deeply divided along clan lines.

The clan rivalries and lawlessness provided fertile ground for the Shabaab to take hold and seize territory, frustrating efforts to set up a central administration.

After a series of transitional governments were formed abroad, a previous parliament was chosen by 135 clan elders and set up in Mogadishu in 2012.

Somalis were promised a one-person, one-vote election in 2016.

But political infighting and ongoing insecurity due to the presence of Shabaab meant Somalis were handed a "limited" election, in which 14,025 specially picked delegates voted for 275 parliamentary seats distributed according to clan.

Another 72 seats in a new upper house were shared out according to region.

The 2016 process is seen as taking the country a step closer to a universal suffrage election now planned for 2020.