Burkina Faso beat 10-man Gabon on penalties to reach the quarter-finals at the Africa Cup of Nations in Cameroon following a 1-1 draw.
Ismahila Ouedraogo netted to give the Stallions a 7-6 win in the shoot-out.
Gabon had Sidney Obissa sent off midway through the second half but grabbed an injury-time equaliser when Bruno Ecuele Manga's header went in off Adama Guira.
Burkina Faso captain Bertrand Traore had missed a penalty before slotting in the opener in the 28th minute.
The Stallions will Tunisia, who beat Nigeria 1-0 later on Sunday, in the last eight on Saturday, 29 January.
A mammoth shootout had seen Herve Koffi save from Gabon midfielder Guelor Kanga and Saidou Simpore immediately send his effort over the bar in the fourth round of penalties.
Abdoul Tapsoba had the chance to win it for Burkina Faso in sudden death after Yannis N'Gakoutou had blazed over, but Jean-Noel Amonome denied him.
However, substitute Ouedraogo kept his nerve after Gabon right-back Lloyd Palun rattled the crossbar to send the Burkinabe through.
It was at times a scrappy encounter in Limbe, marked by several bookings, but also a game which provided moments of quality and drama.
Burkina Faso had spurned several chances to make it 2-0 before the 90 minutes were up in Limbe, but Amonome saved well from Traore, Blati Toure and Guira.
And the Stallions ultimately paid in the 91st minute when Ecuele Manga's header from Denis Bouanga's cross deflected in for a dramatic equaliser.
Tapsoba had an extra-time goal ruled out for offside against Zakaria Sanogo, and Gabon keeper Amonome denied Tapsoba and Ouedraogo in the second added period to send the game to penalties.
Ismahila Ouedraogo won it with the 18th kick of a shoot-out which saw five players miss or have efforts saved
The first flash point came after 14 minutes when Obissa was harshly penalised and booked for a challenge on Issa Kabore which saw the Stallions awarded a penalty.
A red card seemed inevitable at some point, with several Gabon players booked for dissent and Moroccan referee Redouane Jiyed ultimately brandishing 15 yellow cards by the end of the evening.
Aston Villa forward Traore leant back and side-footed against the bar from 12 yards but the Stallions captain made no mistake with his second sight of goal.
Having been released by a perfectly-weighted Dango Ouattara through ball which cut out Gabon centre-back Ecuele Manga, Traore sent a low left-footed finish past the onrushing Amonome and in off the inside of the post from over 25 yards out.
Johann Obiang almost caught out Burkina Faso keeper Koffi from distance and then Aaron Boupendza had an equaliser ruled out for offside before the break.
Gabon lost momentum after having Obisse dismissed for pulling back Ouattara off the ball as the Stallions mounted a counter attack, but a spirited display saw them take the game all the way to penalties.
Yet Patrice Neveu's side, who beat Ghana and drew with Morocco in the group stages, could not pull off another upset against a higher-ranked opponent.
Gabon sent the game to extra-time with a 91st-minute equaliser but were ultimately denied
Burkina Faso defender Edmond Tapsoba:
"This game was a crazy game. We could have finished it in 90 minutes but we missed a lot of chances.
"It was not easy for us but we tried to stay together and work hard.
"We were saying we have to win this game on penalties or in extra time, and we finally won the game on penalties.
"If we win everybody in the country is happy (and) they try to forget everything. I hope this qualification will give peace in Burkina Faso."