Somali crisis: President Ahmed and speaker Aden in deal
After months of squabbling that angered donors and jeopardised gains from Islamist militants, the rival leaders of Somalia's government have agreed to delay elections.
Both President Sheikh Sharif Ahmed and speaker of parliament Sharif Hassan Sheikh Aden will remain in office.
They also agreed to sack the prime minister, sparking large protests on the streets of Mogadishu.
Despite the row, pro-government forces have been gaining ground in the city.
African Union troops have seized territory from the al-Qaeda linked group, al-Shabab.
However, al-Shabab still controls much of southern and central areas of the country.
Islamist militants on Thursday attacked Mogadishu's port, reportedly leaving one person dead.
Under the deal signed in Uganda, the mandates of the president, the speaker and their deputies have been extended until 20 August 2012, when new elections will be organised.
Uganda supplies the bulk of the AU troops and its president last week said Somalia's government should be given another year to consolidate gains against militants.
Otherwise, President Yoweri Museveni said Uganda would withdraw its troops.
The UN had said elections should be held this year.
The UN envoy to Somalia Augustine Mahiga, who helped to mediate the deal along with President Museveni, hailed it as a "breakthrough".
"I am delighted that we have managed to overcome the deadlock," he said.
Mr Museveni had said early polls would allow the militants to reorganise.
Analysts say the row between Somalia's most powerful politicians had brought government activity to a halt.
The BBC's Mohamed Mwalimu in Mogadishu says the demonstration in support of Prime Minister Mohamed Abdullahi Farmajo was one of the biggest in the city for several years.
Some of the protesters said the prime minister was the only senior government official trying to improve social services such as health and education.
Hundreds of people marched and some set fire to tyres to make roadblocks.
A new prime minister is to be named within 30 days.
Earlier this year, the government voted to extend its mandate by a year, but some MPs objected, saying only parliament had the authority to postpone elections.
The current parliament, chosen during a peace conference in 2004, voted to extend its mandate in February for three years.
Somalia has been racked by constant war for more than 20 years. Its last functioning national government was toppled in 1991.