The semi-final saw Nigeria a goal up thanks to a terrible penalty from William Troost-Ekong, leaving South Africa on the brink after their incredible unexpected run to the final.
It then looked like game over in the 85th minute when Napoli star Victor Osimhen tapped into an empty net on the counter-attack, sparking wild celebrations at the Stade de la Paix.
However, Osimhen quickly went from his hands in the air to his hands on his head when it became clear that something was up.
Referee Amin Omar was called to his VAR screen, and it was obvious from the replays that to trigger the counter, Alhassan Yusuf had fouled South Africa's Percy Tau in his own box.
In a remarkable turn of events, Omar waved off the goal and pointed to the spot in an instant, allowing Teboho Mokoena to step up and score the equaliser from the jaws of defeat.
read more afcon news
Egypt appoint new manager who slated Salah after return to Liverpool from AFCON
Forest's Cheikhou Kouyate carries crying teammate off pitch like a baby at AFCON
If that was stunning enough, South Africa then had a free kick in the final minute of stoppage time, and the ball fell to Khuliso Mudau who missed a near open-goal.
In extra time there was more penalty drama when Hlompho Kekana scythed down Terem Moffi who was through on goal.
The incident occurred just on the edge of the penalty box, but VAR was put to good use again as a free kick and red card were given.
Nigeria couldn't convert, and failed to do so for the remaining extra time, leading to a penalty shoot-out which they won.
Most read in Football
Jon Dahl Tomasson on the verge of quitting Blackburn before glamour FA Cup tie
Little-known rule could force Man City owners to give up stake over European qualification
Tony Bellew told to 'calm down' after furious Everton and Premier League rant on talkSPORT
Brighton beat Premier League rivals to agree deal for highly-rated teenager
Goalkeeper Stanley Nwabali was the hero as the spot-kicks finished 4-2, capped off by Leicester's Kelechi Iheanacho sealing the deal.
The striker ran off whirling his shirt around his head, wit Nigeria in their first AFCON final since victory in 2013, and they will face either DR Congo or hosts Ivory Coast.