Nigeria sneaked into the Africa Cup of Nations semi-finals when defender William Troost Ekong scored with one minute remaining to give them a 2-1 win over a gallant South Africa as the tournament served up more drama on Wednesday.
Troost Ekong, left unmarked by the South Africa defence, turned the ball in with his knee from a corner just as Nigeria seemed to be in danger of throwing away a game they had dominated for more than an hour.
Samuel Chukwueze, recalled to the side after missing the previous round, put the Super Eagles in front when he scored at the second attempt in the 27th minute.
Nigeria stayed in control, missed chances and paid the price when Bongani Zungu headed an equaliser in the 71st minute with South Africa's first shot on target.
The goal was initially ruled offside but then awarded after a VAR check -- the first major intervention by technology since it was introduced for the quarter-finals.
Nigeria, who will meet Ivory Coast or Algeria in the last four, went ahead with the first really dangerous attack of the match.
Alex Iwobi burst down the left and pulled the ball back into the area to Chukwueze whose first effort was blocked by a defender but scored after it rebounded back to him.
Chukwueze, overlooked for the 3-2 last 16 win over Cameroon, was a constant menace down the right and created another chance after skipping past his marker but Dean Furman made a timely interception to deny him.
Nigeria looked too strong all-round for their rivals and nearly extended their lead early in the second half with a 25-metre free kick from Oghenekaro Etebo but Ronwen Williams turned it on the bar.
South Africa, who sensationally knocked out hosts Egypt in the previous round, struggled to get a look-in but the Super Eagles repeatedly failed to turn the mazy runs of Ahmed Musa and Chukwueze into goals.
Then, from out of the blue, South Africa equalised as Percy Tau lofted a free kick into the area, it was flicked on and superbly headed in by Zungu. It was initially disallowed but then given by a VAR check that took nearly three minutes.
Extra-time was looming until Nigeria won a corner on the left, Williams missed the ball and Troost Ekong prodded it home.