Nigeria needed two late penalties from cool-as-ice Victor Moses to defeat Ethiopia 2-0 on Tuesday set up a quarterfinal with African Cup of Nations favourites Ivory Coast at the weekend.
All the drama at the Royal Bafokeng Sports Palace unfolded in an electric final 10 minutes of a tense, fraught match which was being played simultaneously with the other Group C game between Burkina Faso and champions Zambia in Nelspruit.
With 10 minutes remaining Nigeria were facing elimination.
Both games were level at 0-0 and with Zambia and Nigeria having identical points and goal records, the former were set to qualify by virtue of a better disciplinary record in terms of red and yellow cards.
That all changed though as Ethiopia defender Alula Girma brought down Moses after 80 minutes and the Chelsea forward kept his nerve to beat goalkeeper Sisay Bancha.
A Nigerian counter-attack five minutes later then left Moses in space and bearing down on goal from the left.
Bancha rushed from his line to scythe the youngster down and was sent off after being shown a second yellow card by Moroccan referee Bouchaib Al Ahrach.
He became the second Ethiopia keeper to be dismissed in the tournament after Jemal Tassew was red-carded against Zambia and Bancha was off the field by the time Moses was ready to take the second penalty of the night.
The Nigerian again had to hold his nerve while midfielder Addis Hintsa took a long time to find a goalkeeper's jersey that did not clash with the rest of his team.
Hintsa went in goal because Ethiopia had already used all three substitutes and the first time he touched the ball was to pick it out of the back of the net after Moses scored from the spot.
The first penalty went right, the second left and Nigeria were on their way into the knockout round.
This video is not available in your region
Victory eased the pressure on Nigeria coach Stephen Keshi after two opening draws and he was understandably delighted.
"I was not aware of what was happening in the other game," Keshi told reporters. "I was not really aware we were absolutely level but in the end it did not matter as the Gods smiled on us."
He said Sunday's match against old rivals Ivory Coast would not be like Tuesday's game.
"They are a different side but we will enjoy playing them," added Keshi. "It is going to be tough but it will be just as hard for them - there will be no second chances for either team."
Ethiopia coach Sewnet Bishaw made eight changes from the side beaten 4-0 by Burkina Faso in their previous game and, even though they only had one point from the opening two matches, stood a chance of qualifying on Tuesday.
They never looked like doing so as Nigeria, with Sunday Mba outstanding while midfield colleague John Obi Mikel was closely marked by two opponents, controlled the game for long periods.
Bishaw, who led Ethiopia back to the finals for the first time in 31 years, said: "We are out but we have gained so much experience and we will build on that for the future.
"We also need more experience. We cannot make the kind of mistakes that led to having two goalkeepers sent off in a tournament."
Despite a low attendance, the fans made a lot of noise while the Ethiopian supporters displayed a banner saying sorry for their conduct in the Zambia game last week when they threw missiles on the field.
"We apologise for our behaviour but we love the game," it said.
"They are the best fans in the world," Bishaw added.