Civilians have been fleeing the fighting in the north-east
Representatives of the Democratic Republic of Congo Government and two main rebel groups have agreed to set up a transitional government and army, in which all will participate.
But the deal was nearly scuppered by heavy fighting in the north-east, where Uganda forces pushed a small rebel group, the Union of Congolese Patriots (UPC), out of the strategic town of Bunia.
The largest rebel group, the Rally for Congolese Democracy (RCD) which is allied to the UPC, threatened to pull out on what was supposed to be the last day of discussions over a new power-sharing agreement.
But the obstacle was overcome after they returned to negotiations in Pretoria and a draft transitional constitution was agreed.
Rebels said the fighting at Bunia - and allegations of DR Congo Government involvement - had cast a shadow over the day.
"This day should have been inscribed in gold in the annals of history of our country. Unfortunately this day is also inscribed in blood," said Olivier Kamitatu, secretary-general of
the other main rebel group, the Congolese Movement for Liberation (MLC).
The agreements came at a meeting designed to build on the peace deal signed in December.
The plan is for democratic elections to be held in DR Congo in two years time - the first since independence in 1960.
DR CONGO'S WAR
Seven foreign armies
At least 2 million dead
Disease and abuses widespread
The Congolese ambassador to South Africa, Ben Mpoko, described the signing as historic.
He said the transitional government would be headed by current President Joseph Kabila and four vice-presidents - two of whom would come from the ranks of the former rebels.
The DR Congo Government said it was prepared to allow an international force under the UN in the capital and other major towns, and all sides agreed to draw up a new national army to include
soldiers from all of the warring factions.
Ugandan troops took over the town of Bunia after a day of clashes with UPC fighters.
UPC leader Thomas Lubanga said his fighters had been forced to pull out of the town, which they used to control "after very heavy clashes".
Each side has blamed the other for starting the fighting.
Uganda, which has a base outside Bunia at the airport, used to support the UPC, but correspondents say relations have soured since the rebels demanded that the Ugandan soldiers withdraw from the region.
Although the vast majority of foreign troops have left the Democratic Republic of Congo after a series of peace deals, the UN asked Uganda to keep troops behind in Bunia to keep warring factions apart.
Uganda kept some 2,000 soldiers stationed in and around Bunia.
In February, Uganda President Yoweri Museveni agreed to pull out their remaining troops by 20 March.
Bunia's population has doubled to 200,000 in recent months as people fleeing fighting elsewhere in Ituri province have flooded in.
Women's accounts of surviving war in Africa
Earlier this week the United Nations announced they would send a team to the north-east to investigate reports of a massacre in Bogoro, just south of Bunia.
Mr Lubanga said that hundreds of civilians had been killed by militia allied to the DR Congo Government.
More than two million people are believed to have died as a result of the war which began in 1998, and at one stage dragged in half a dozen foreign armies.