Somalia's interim government and a rival Islamist militia that holds much of the south of the country have agreed in principle to form a national army.
Gunmen loyal to Islamic courts took control of Mogadishu in June
However, this depends on a political agreement being reached at further talks on 30 October in Sudan.
The rivals also agreed to avoid seeking aid from foreign powers and affirmed an earlier truce, threatened by the Islamists' recent territorial gains.
Somalia has had no effective central government since 1991.
The BBC's Yusuf Hassan at the talks in Khartoum says the agreement came unexpectedly quickly.
He says that both sides need each other, with the government weak and the Union of Islamic Courts (UIC) wanting international recognition.
East African leaders are meanwhile meeting in the Kenyan capital, Nairobi, to discuss the Somali government's request for a peacekeeping force - an idea strongly rejected by the UIC.
Several thousands people marched through the capital, Mogadishu, in protest at the peacekeepers.
"We will wage a holy war against them," the crowd shouted.
The interim government has the support of the UN but it controls only a small area of the country around its base in Baidoa, about 250km from the capital, Mogadishu.
The Union of Islamic Courts took control of Mogadishu in June as well as several central and southern parts of the country.
Under the deal struck on Monday, the parties agreed "to build armed forces like an army and police" incorporating militias loyal to the Islamic courts, the government and others.
Details on the formation of the new force are expected to be fleshed out after the two sides have resolved key political differences.
The deal struck on Monday also calls for both sides to resist involving Somalia's neighbours in the conflict.
The Islamists have accused the government of bolstering its defences with troops from Ethiopia, while they in turn have been accused of using military backing from Eritrea.
Under Monday's deal, both sides will also be required to respect an earlier truce, struck in June.
The two parties have been accusing each other of violating the June deal.