TEHRAN (Tasnim) - Somali troops retook the presidential palace in the capital Mogadishu after al-Shabab fighters forced their way in and exchanged heavy gunfire with soldiers and guards.

Loud explosions and gunfire could be heard as troops tried to repel the intruders on Tuesday evening, Al Jazeera reported.

After more than two hours of fighting, Somalia's presidency said on Twitter that "the shameful attack" had been foiled by Somalia's armed forces fighting alongside African Union peacekeepers.

Al-Shabab claimed responsibility for the attack.

Somali President Hassan Sheikh Mohamud was not inside the palace at the time of the attack, but the prime minister and the speaker of parliament were, said Captain Mohamed Hussein, a senior police official.

The presidency said both President Mohamud and Prime Minister Abdiweli Sheikh Ahmed were safe.