South Africa says it will host the Africa Cup of Nations in 2013 instead of Libya.
The two countries have agreed to swap the rights to host the event, so Libya will take on the tournament in 2017.
The deal was announced by South Africa's football association (Safa) and is subject to the Confederation of African Football's (Caf) approval.
Libya's hosting of the 2013 tournament had been in doubt for some time because of the continuing violence there.
"Safa and the Football Federation of Libya have signed an agreement with regards the hosting of the 2013 and 2017 Africa Cup of Nations tournaments," Safa said in a statement.
"Libya will host the 2017 Afcon [Nations Cup] which had been awarded to South Africa, while Safa will take over the hosting of the 2013 Afcon tournament as well as the 2014 African Nations Championship [the tournament for locally-based players], which was supposed to be played in Libya.
"The agreement comes following the political upheaval in Libya but is subject to ratification by Caf at its next Executive Committee meeting."
Caf's next Executive Committee meeting is scheduled for 27-28 September in Cairo.
"It is only the executive committee that has the mandate to give the hosting rights to a country," Caf's Director of Communications Suleiman Habuba told the BBC on Thursday.
One issue for Caf to deal with is its agreement, back in 2006, that Nigeria would have the right to step in if any of the Nations Cup hosts named that year were unable to fulfil their commitments.
However, the Nigeria Football Federation appears to have no political will to host the 2013 finals.
"The board of the Nigeria Football Federation (NFF) wish South Africa all the best," NFF spokesman Ademola Olajire told BBC Sport.
"The decision between both countries must be applauded and respected by all. We wish them all the best and will focus solemnly on qualifying for the 2012 African Cup of Nations."
South Africa took over the hosting of the African Under-20 tournament from Libya earlier this year.