Addis Ababa: Somalia's President Abdullahi Yousuf and his prime minister signed a deal on Tuesday to work together after a weeks-long rift that threatened to wreck their interim government.

Yousuf fell out with Prime Minister Nour Hassan Hussain earlier this month after Hussain sacked Mogadishu's powerful mayor, who was a key ally of the president.

Both men have been locked in crisis talks for days with officials in neighbouring Ethiopia.

"We hope the agreement will end the differences between the Somali leaders," Ethiopia's Foreign Minister Seyoum Mesfin said after the pair signed the deal in Addis Ababa.

"Ten days ago, the very existence of TFG [transitional federal government] was at a critical point. The differences were a deciding factor that makes or breaks the transitional period, including the peace agreement in Djibouti."

Addis Ababa has propped up Yousuf's government since allied Ethiopian and Somalia troops stormed into Mogadishu over the New Year of 2007 and retook the capital from an Islamist movement.

The rebels have waged relentless Iraqi-style attacks against government positions since then in violence that has killed more than 8,000 and forced another 1 million from their homes.