* Second soldier succumbs to wounds
* President was abroad at time of attack, PM safe (Adds death toll, Shabaab comment)
By Abdi Sheikh
MOGADISHU, Jan 29 (Reuters) - A suicide bomber blew himself up near the Somali presidential palace on Tuesday, killing at least two soldiers in a strike apparently aimed at the country's leaders, a palace guard at the scene said.
Officials working in the palace and guards said Somali President Hassan Sheikh Mohamud was abroad at the time of the blast and Prime Minister Abdi Farah Shirdon Saaid, whose house was near the site of the explosion, was safe.
The blast was the first this year in Mogadishu, where security has improved greatly since Al Shabaab - Islamist rebels allied to al Qaeda - were driven from the capital by African peacekeepers in late 2011.
The group - which wants to impose its strict version of Sharia or Islamic law - is fighting to topple Mohamud, whose election last year was the first such vote since warlords ousted military dictator Mohamed Siad Barre in 1991.
"The man blew up himself near a wall between the Ethiopian embassy and the Somali PM's residence," Ahmed Ali, a Somali soldier at the presidential palace told Reuters.
The two buildings are inside a sprawling compound that also houses the presidential palace.
"One guard died there and then. Another died of his wounds. They were all the guards of the PM," said Ali. "The man was an al Shabaab defector. He had a gate pass, an identity card of the national security."
Guards at the palace who declined to be named said the blast partially damaged a small room made of iron sheets where the prime minister's guards are stationed, but little else was damaged. Buildings and cars within the compound were untouched.
OUSTED FROM URBAN CENTRES
The guards said the bomber was known to them, and frequently visited the palace. When he came by on Tuesday morning, the guards took the suicide bomber through a routine inspection and found he was clad in an explosive jacket.
The guards tried to prevent him from detonating his device, but it went off - killing one instantly and wounding two others.
Al Shabaab was not immediately available for comment on the attack.
The group fled to southern Somalia after quitting Mogadishu but in late September Kenyan troops forced it to withdraw from the port of Kismayu, its last major urban stronghold in the Horn of Africa nation.
That appears to have ended it as a quasi-conventional military force, though Al Shabaab remains a threat and has vowed to step up suicide bombings and hit-and-run attacks.
On Jan. 17 the group said it had executed a captive French agent after a French commando mission to rescue him failed. (Writing by James Macharia; Editing by Jon Boyle)