Nigeria qualified for the next round of the Africa Cup of Nations after two late Victor Moses penalties gave them a crucial win against Ethiopia.
Moses, 22, opened the scoring from the spot after he was fouled by defender Alula Girma with 10 minutes to go.
The winger earned the second penalty when he was brought down by goalkeeper Sisay Bancha, who was sent off.
If Nigeria had gone out of the Africa Cup of Nations, it would have been the first time since 1982 they had not made the quarter-finals.
If Moses had not scored they would have lost a quarter-final spot to Zambia due to a worse disciplinary record.
Holders Zambia and Nigeria had come into their last round of group fixtures level on points and with an equal goal difference after they drew both their opening games 1-1.
Before Moses’s intervention, his side had been set for an early trip home as they had collected more yellow cards.
Aware of the potential for that scenario, the Super Eagles began in Rustenberg with an intent absent in the tournament so far.
Defender Efe Ambrose – recalled to the team after missing out against Zambia through suspension – headed a Moses free-kick over the crossbar when well positioned, before Bancha was alert to stop Ikechukwu Uche reaching an incisive John Obi Mikel through-ball.
Some more sharp play from Nigeria saw another chance go to waste when a selfless cut-back from Uche was blazed well over by rampaging left-back Elderson Echiejile.
While struggling to retain possession in their usual manner, Ethiopia did sporadically threaten with their set-piece delivery.
Nigeria head coach Stephen Keshi had decided not to select fit-again captain Joseph Yobo, and in the 32-year-old’s absence, the Super Eagles struggled to convincingly deal with high balls played into their penalty area.
Saladin Seid headed one Ethiopia corner over, while a number of other crosses caused panic at the back for Nigeria.
Dead balls were also causing a problem at the other end of the pitch, and Echiejile stung Bancha’s fingertips with a powerful header from a deep Moses corner.
Nigeria’s suspect defending had already seen them surrender late leads against Burkina Faso and Zambia, and a comical misunderstanding between retreating winger Sunday Mba and right-back Ambrose played in Ethiopia danger man Seid but his shot was deflected harmlessly into goalkeeper Vincent Enyeama’s hands.
The Walyas could then have been reduced to 10-men before the interval after Degu Debebe put in a high, two-footed challenge on the influential Mikel that was only punished with a yellow card by referee Bouchaib Al Ahrach.
Nigeria had begun to lose momentum in the final minutes of the first half and Ethiopia were the team to begin the brightest after the break.
Centre-back Kenneth Omeruo – who had earlier wasted a decent chance when a deflected shot fell to him in the Ethiopia box – was at his sharpest as he stretched to deny Seid a clear header on goal.
Nigeria finally began to show some real intent with 20 minutes to go as they began to pick up the tempo as the threat of making only their third group stage exit in the Africa Cup of Nations drew nearer
This fate looked to have been avoided as centre-back Godfrey Oboabona rose to powerfully meet a corner but his header was cleared off the line by the diligent Abebaw Butako.
Undaunted by the clearance, Nigeria continued to pick up the pace and the exciting Moses was felled by a tired challenge in the area after he had skilfully cut inside Girma.
The Chelsea winger exhibited none of the pressure surrounding his penalty as he calmly sent Bancha the wrong way.
Nigeria had barely finished their jubilant celebrations, though, before their hope of progression was nearly in doubt again when Seid was picked out in the box but Enyeama athletically tipped his effort to safety.
Qualification then looked secured as Moses charged down on goal and was tripped by Bancha. The referee instantly followed up his decision to point to the spot with a deserved second yellow card for the Walyas keeper.
With Ethiopia already using their three substitutions, Moses slotted past midfielder Addis Hintsa who was forced to be a stand-in goalkeeper.
As Zambia were unable to put on a late surge of their own in the other Group C game, Nigeria will now face tournament favourites Ivory Coast in the next round.