Agadir - Nigeria clawed back from the brink of defeat to edge Angola 2-1 after extra time on Sunday in cold, windy Tangiers and book an African Nations Championship (CHAN) semi-final against Sudan.
In the last quarter-final, former champions Libya pipped Congo Brazzaville 5-3 on penalties after a 1-1 draw in southern city Agadir and they will face hosts Morocco for a place in the final.
Both semi-finals are scheduled for Wednesday, with the final next Sunday offering a record $1.25 million (about one million euro) first prize in the fifth edition of the biennial competition.
Nigerian Anthony Okpotu atoned for several misses in an enthralling quarter-final against Angola by equalising during the first minute of stoppage time in northern Morocco.
A free-kick was nodded forward by Rabiu Ali, at 37 the second oldest footballer in the tournament, and Okpotu poked the ball into the net from close range.
The goal tilted the momentum toward Nigeria in the tournament for home-based footballers and Ikechukwu Gabriel struck the winner on 109 minutes.
Substitute Gabriel took the ball across the edge of the penalty area past several opponents before unleashing a low shot into the corner of the net.
Angola had taken the lead after 55 minutes when an attempted clearance struck Va -- one of many Angolans who use Brazilian-style nicknames -- and landed in the net.
Nigeria reacted to falling behind by attacking relentlessly and when a Gabriel header hit the post, it rebounded into the face of goalkeeper Landu before being cleared.
Gabriel later blazed over when one-on-one with Landu as Angola clung desperately to their lead as they tried to avoid a whitewash of quarter-finalists from southern Africa.
Namibia and Zambia were eliminated Saturday by Morocco and Sudan respectively from a competition no country from the south of the continent has won.
It is the second time Nigeria have reached the Nations Championship semi-finals - they lost on penalties to bitter rivals Ghana in South Africa four years ago.
Libyan Saleh Taher Saeid volleyed a loose ball into the net after 15 minutes when Congolese goalkeeper Barel Mouko did not get much distance on his punched clearance of a cross.
It was the third goal of the tournament for Saeid, and Junior Makiesse levelled on 37 minutes by scoring his second goal in Morocco with a close-range shot.
Libya converted all five shootout penalties with Sand Masaud netting the decisive spot-kick after Mouko blazed the third Congolese penalty over the crossbar.
Although restricted to footballers playing in their country of birth, Nations Championship matches carry full international status and count toward the monthly FIFA rankings.