Hundreds of heavily-armed gunmen pulled out of strongholds in Mogadishu they had occupied since late April, when a long-running turned deadly with clashes erupting between rival factions of the security forces.
Under a deal reached by the warring sides this week, opposition troops began leaving their positions in the capital, and key roads sealed off with sandbags and machine guns were opened once more.
"We are sending our forces back to the frontline position to defend the country and its people," said Mahad Salad, an opposition lawmaker, at a camp outside Mogadishu where troops assembled after pulling out of the city.
Mogadishu had been on edge since February, when President Mohamed Abdullahi Mohamed's term ended before elections were held, and protesters took to the streets against his rule.
Read more:
But a resolution in April to extend his mandate by two years split the country's fragile security forces along all-important clan lines.
Soldiers loyal to influential opposition leaders began pouring into the capital, where clashes broke out with pro-government troops, killing three.
Exodus
The fighting drove tens of thousands of civilians from their homes and divided the city, with government forces losing some key neighbourhoods to opposition units.
Under pressure to ease the tension, Mohamed abandoned his mandate extension and instructed his prime minister to arrange fresh elections and bring together rivals for talks.
"These forces came to the rescue of the people, and have taught a new lesson which will be remembered in future. They refused a dictatorship, and have forced the democratic governance process to continue," opposition lawmaker Salad said.
Indirect elections were supposed to have been held by February under a deal reached between the government and Somalia's five regional states the previous September.
But that agreement collapsed as the president and the leaders of two states, Puntland and Jubaland, squabbled over the terms.
Months of UN-backed talks failed to broker consensus between the feuding sides.
In early May, Mohamed relaunched talks with his opponents over the holding of fresh elections, and agreed to return to the terms of the September accord.
Prime Minister Mohamed Hussein Roble has invited the regional leaders to a round of negotiations on May 20 in the hope of resolving the protracted feud and charting a path to a vote.
The international community has threatened sanctions if elections are not held soon, and warned the political infighting distracted from the fight against Al-Shabaab, the militants who control swathes of countryside.
Major General Ali Araye Osoble told opposition troops outside the capital that it was time to return to duty.
"I order that you return to your positions and fulfil your commitments in the fight against Al-Shabab," the opposition commander said.
Follow us on , and to stay connected