Substitute Gabriel Okechukwu scored a 108th minute winner for Nigeria who came from behind to beat a resilient Angola side 2-1 on Sunday in Tangiers to book a place at the semis.
Angola took an early second half lead through Vladimir Va after Emeka Atuloma's clearance bounced off him and went past goalkeeper Ikechukwu Ezenwa in the Nigeria goal on 55 minutes.
The Super Eagles dominated the close contest and should been in front in the opening minutes when striker Anthony Okpotu raced through on goal with only Angola keeper Landu Mavanga to beat, he instead tried to dribble and went down in the box as Angola cleared the opportunity.
Nigeria Moses Osas bust through the right to send in Emeka Ogbugh whose effort forced a save from the excellent Landu in the Angola goal.
Angola threatened from a corner which saw Braulio Adelio heading just wide off Ezenwa's goal on 14 minutes. Mano Luis also tried his luck from a distance but failed to trouble Ezenwa.
Veteran Nigeria forward Rabiu Ali missed from close range following a through ball from Solomon Ojo but his under hit chip fell into the hands of Landu.
Ezenwa denied Mano with two successive saves on 34 minutes after Afonso played him through with a clever flicked past into the area only to be denied by the shot stopper, , who was later adjudged Total Man of the Match.
Okpotu who lead Nigeria's attack missed another opportunity on the stroke of half time with his effort blocked for a corner after Landu fumbled Ojo's cross in the Angola defence.
Five minutes into the second half, Okpotu missed yet again dragging his right foot shot off target.
Va broke the deadlock when Atuloma's clearance bounced off his body and over the helpless Ezenwa to give Angola the lead and added pressure on the much fancied Super Eagles.
The Eagles responded with Atuloma releasing a fierce shot just over the goal from distance and Gabriel Okechukwu's header bouncing against the foot of the post with 15 minutes of normal time remaining.
Ezenwa pulled another top save with time running out for the Super Eagles with an athletic save from Afonso's powerful strike.
Okpotu finished off Rabiu Ali's header past Landu to draw Nigeria level and force the game to extra time much to the delight of their fans.
Okechukwu secured Nigeria a place in Wednesday's semi-final in Marrakech against Sudan with an solo effort drifting infield from the right skipping away from a couple of Angola challenges before firing low past Landu to win it.
Total Man of the Match: Ikechukwu Vincent Ezenwa (Nigeria)
Ikechukwu Ezenwa (Total Man of the Match)
I have to thank the team especially the coach who was very calm in the technical area pushing the team and believing that we will get the win. The performance was great because we continued to push and tried to get the goal after going down and we did just that in the last minute.
I'm happy with my performance and having Gernot Rohr here watching, I believe that will help me with the senior national team.
Salisu Yusuf (Head Coach, Nigeria)
Today's game was the most difficult for us in the tournament as we fought for 90 minutes against a good team. We never lost faith in our players because we were creating chances and the more you do that the chances of scoring are higher.
I'm so confident about Anthony Okpotu and we believe in him and he has been scoring despite missing some chances but he will be much better in the coming matches.
We never understimated Angola, they play good football and are a good team but the important thing was to win and we won.
Srdan Vasiljevic (Head Coach, Angola)
Football is sometimes not favourable. We scored and Nigeria equalized in the last minute before winning it in extra time. We thought it was enough to hold on for a win but it wasn't enough and we lost. I hoped to have a good result but this is football for you.
The tournament provides us with a lot of experience which will help us going forward because this is a tournament that gives great experience to our players.