The agreement must still to be ratified by the Confederation of African Football, who will meet in Cairo next month.
“In terms of the agreement, Libya will host the 2017 finals which had been awarded to South Africa, while SAFA will take over the hosting of the 2013 tournament,” SAFA said in a statement.
South Africa this year filled in at short notice for Libya, currently embroiled in civil conflict, by hosting the African Youth Championship. They had just six weeks to put together the eight-team tournament.
South Africa had been expected to take over from Libya for 2013 given a comprehensive infrastructure from the World Cup last year made them a logical choice.
Algeria had also expressed an interest as stand-by hosts and Nigeria had been previously delegated as a reserve hosts.
The next Nations Cup finals are to be co-hosted by Equatorial Guinea and Gabon in January and February after which the tournament switches to every odd year.
Morocco are the hosts in 2015.
Short link: