Updated

The presidents of Sudan and South Sudan signed economic and security agreements Thursday that will allow a resumption of oil exports from South Sudan. The two countries also reached deals for a demilitarized zone between their borders and a cessation of all hostilities that brought the countries to the brink of all-out war just a few months ago.

Sudan President Omar al-Bashir and South Sudan President Salva Kiir signed the agreement in Ethiopia's capital, where they have been holding talks since Sunday. The talks were originally scheduled to last only a day. The sides could not agree on a shared border or on how to address the disputed region of Abyei.

Both sides have been under pressure from the U.N. Security Council to resolve the outstanding issues or risk sanctions. South Sudan broke away from Sudan last year after an independence vote that was the culmination of a 2005 peace treaty that ended decades of war that killed more than 2 million people. But the border was never defined, and South Sudan suspended oil production in January after accusing Sudan of stealing its crude, which is transported in pipelines through Sudan. Border clashes escalated in April when South Sudan troops took over an oil town in a region Sudan claims as its own.

With the deal sealed Thursday, officials say only "technical works" remain for oil exports to resume soon. Some officials have said it will take months to clear the pipelines and get oil flowing again.

The security agreement was signed by the two countries' defense ministers, while lead negotiators inked economic and trade agreements. AU mediators say the two sides also signed a deal to let their citizens freely move between, reside in and work in both countries.

Bashir and Kiir spent four days in an apparent effort to overcome the most contentious issues -- finalizing a border and determining the status of the border region of Abyei -- but failed.

The freeze on oil production has cost both countries millions of dollars in lost revenue. An economic crisis sent inflation soaring and pushed food prices beyond the reach of ordinary citizens, said Jose Barahona, the top official for the aid group Oxfam in South Sudan, who called the agreements encouraging.

"But the two nations will continue to face an uncertain future until there is agreement on Abyei and the other contested areas, and efforts are stepped up to resolve the conflicts in Southern Kordofan and Blue Nile," he said, referring to two areas in Sudan where residents are seen to be sympathetic to South Sudan. Fighting in the region has sent 170,000 refugees fleeing over the border into South Sudan.

Samson Wasara , a professor of economics at Juba University in South Sudan, said the resumed oil exports -- from which Sudan will take transport fees -- would help ease tensions but that the new demilitarized buffer zone will provoke more conflict if the borders are not clearly defined. He noted that the demilitarized zone between North and South Korea has been a source of tension for decades.

"Proper border demarcation will reduce the chance of encroachment by both countries. But in order to do this, the international community must pressure Sudan and South Sudan to agree to something definite. If this is not sorted out quickly it will lead to later tension," Wasara said.

African Union mediator Thabo Mbeki, Ethiopia's Communications Minister Bereket Simon and diplomats witnessed the agreement's signing ceremony at the Sheraton Addis hotel. The ceremony started with a minute of silence for the late Ethiopian Prime Minister Meles Zenawi, whom Mbeki credited with being instrumental in facilitating the talks.