The deal, reached after more than three weeks of negotiations, will throw both economies a lifeline. It should for now prevent any resumption of the kind of fighting that broke out along the border in April - the worst violence since South Sudan seceded in July 2011 under an agreement that ended decades of civil war.
But the neighbours still deeply distrust each other and have a history of failing to implement agreements.
Faced with the threat of U.N. sanctions and economic collapse, Sudanese President Omar Hassan al-Bashir and his South Sudanese counterpart Salva Kiir agreed after four days of summit talks to set up a demilitarised border buffer zone.
The deal will allow landlocked South Sudan to resume oil exports through Sudan, providing both battered economies with dollars. The south had shut down its entire 350,000 barrels a day of output in January after the countries argued about transit fees.
"The agreement will be signed tomorrow," El-Obeid Morawah, spokesman for Sudan's Foreign Ministry, told Reuters. Atif Keir, spokesman for the southern delegation, confirmed the deal.
But despite pressure from the African Union, the United States and other Western powers, the two sides failed to settle the fate of at least five disputed oil-producing regions along the border.
Tensions over the unmarked 1800km common border spilled over into fighting in April, when South Sudan's army briefly occupied the Heglig oilfield, vital to Sudan's economy.
"We will talk about the claimed areas in future talks," Morawah said.
The neighbours were also unable to reach a solution for the border region of Abyei, which has symbolic significance to both and is rich in grazing lands. Plans for a referendum have failed over the question of who should participate.
"The African Union will decide on a final solution," Keir said.
The security deal will be signed on Thursday, but it will take several months to restart southern oil production as the export pipelines were filled with water to prevent them becoming blocked, and some fields were damaged during fighting.
The U.N. Security Council had set a September 22 deadline for a broad deal to end hostilities but that was informally extended until the end of the Addis Ababa summit.
The African Union even postponed a signing ceremony for the border security deal at the last minute on Wednesday to make a last push for at least some agreement on Abyei, but to no avail.
The border deal provides for both armies to pull back 10km from the frontier. Special arrangements will be made for a strategic strip of land called Mile-14, which is important to Arab tribes allied to Sudan.
But the lack of a permanent solution for the disputed regions will pose future risks to border security. Their fate may ultimately be settled only in international arbitration, a lengthy process.
Furthermore, AU mediator Thabo Mbeki failed to achieve tangible progress in indirect talks between Sudan and the rebel Sudan People's Liberation Movement-North (SPLM-North), which is fighting the Sudanese army in two areas bordering South Sudan.
The SPLM-North is part of an alliance with rebels from the western region of Darfur who want to topple Bashir. Sudan refuses direct talks as it accuses the south of supporting the SPLM-North, which controls some territory on the Sudanese side of the border.
Diplomats say each side supports rebels on the other side. South Sudan last weekend accused Sudan's army of having airdropped weapons to a militia fighting the government. Sudan denied this.
A deal reached last month to allow aid into rebel-controlled areas has not been implemented yet.