Rival political leaders have signed a deal they hope will reunite Somalia after 15 years of division.
The speaker (l) and president (r) met for the first time in six months
Under the agreement, the transitional parliament will assemble in the next 30 days for the first time on Somali soil.
The parliament includes representatives of the main clans and militia groups and last met in Kenya a year ago.
The Yemen talks have been led by the president who is based outside the capital and the parliamentary speaker allied to militias who run Mogadishu.
The head of the BBC Somali service, Yusuf Garaad Omar, says this is a major breakthrough for the peace process, which has stagnated since the transitional government was sworn in more than a year ago.
However, there is no mention in the agreement about where the parliament and its 275 MPs will be based or where they will meet in a month's time.
Somalia's Foreign Minister Abdullahi Sheikh Ismail told the BBC the agreement was an important step as it had removed "mistrust and misunderstanding" between the country's divided politicians.
President Abdullahi Yusuf has previously refused to move to Mogadishu on security grounds, because it is controlled by rival militias and had set up his government in the town of Jowhar - some 90 km away.
But Speaker Sharif Hassan Sheikh Adan and many MPs disagreed and went to the capital to try and establish a rival administration.
"I have no doubt whether today or tomorrow or after tomorrow that there will be a unanimous understanding about where to go," Mr Ismail told the BBC's Focus on Africa programme, saying negotiations were ongoing.
"The realities on the ground of Somalia are what they are, we cannot change them at all, but the most important thing is the unanimity of the political vision and that is there," he said.
A Yemeni official close to the talks told Reuters news agency that the leaders had deliberately omitted the location of the government to avoid angering warlords.
"In principle, they agreed that the government will first move to Baidoa and then Mogadishu," the official said.
The five-part agreement also calls for respect for the constitution under which Somalia's failed central government and parliament was established in 2004.
It calls for all groups to put aside their differences to unite the country and government, which was elected by parliament when it met in Kenya in late 2004.
But it does not say when, or even if, President Yusuf should move the central government back to Mogadishu.
Correspondents say Mr Yusuf's eventual return to the capital is likely to depend on an agreement by the militias to withdraw from the streets of Mogadishu.
To avoid the need for the controversial deployment of foreign peacekeepers, the leaders called on Somalis to disarm themselves.
The reaction from people in Mogadishu has been positive says the BBC 's Hassan Barise - but there has been no reaction from any of the powerful Mogadishu warlords yet.
The country, a former Italian colony, has been controlled by rival militias since 1991 and has become one of the poorest countries in the world.
The international community has made it very clear that it will not fund the new government if it remains divided.
Mr Ismail called on the international community to recognise the progress made in Yemen.
"I am not a doomsday predictor. I don't share the pessimistic approach of the international press. This is a long journey and we will continue," he said.
On Wednesday, Italy became the second European country after Belgium to formally recognise Somalia's transitional government after the visit of Italian Deputy Foreign Minister Alfredo Mantica to Jowhar.
China, the Arab League and the African Union also have diplomatic representation in Jowhar.