Landlocked South Sudan took three-quarters of Sudan's oil production -- the lifeline of both economies -- but needs to sell its crude through northern export facilities. Both countries, Sudan and S Sudan, have failed to agree on a transit pipeline fee. Juba shut down last month its entire oil output after Khartoum started seizing southern oil as compensation for what it calls unpaid fees.
Sudan's President Omar Hassan al-Bashir warned last week that the tensions with South Sudan, which became independent in July, could lead to war between the two countries.
Former South African President Thabo Mbeki, who has been trying to mediate an end to the tensions, said the deal was a "non-aggression pact" aimed at avoiding any armed conflict.
"This deal addresses those issues," Mbeki told reporters when asked whether the agreement would defuse the threat of war.
The security agreement, brokered by the African Union in Addis Ababa, said the two sides agree to "respect each other's sovereignty and territorial integrity, non-interference in internal affairs, rejection of the use of force, equality and mutual benefit; and peaceful coexistence".
Apart from oil, Sudan and South Sudan need to find a solution to the disputed border region of Abyei and to mark the joint border. Both countries often accuse each other of supporting rebels on the other's territory.