Co-hosts Gabon netted a winner with virtually the last kick of the game to seal their quarter-final place at the 2012 Africa Cup of Nations with a 3-2 Group C victory over Morocco.
The North African side become the latest top name to head home after the first round having suffered two defeats in two games, this one in the cruellest of fashions. But take nothing away from the Gabonese, who fought bravely in front of a vociferous home crowd and based on the balance of play deserved their win.
Gabon netted through goals from Pierre Aubameyang, Daniel Cousin and Bruno Mbanangoye Zita, while skipper Houssine Kharja scored twice for the Moroccans. Kharja put his side ahead on 24 minutes with a fine individual goal from nothing. The defenders stood off him and he simply stroked the ball home past a helpless Didier Ovono in the home goal.
The game was a tight contest throughout and at times lacked quality, too many misplaced passes and not enough creativity amongst all the huff and puff. It really sparked to life in the closing stages, when Aubameyang netted a deserved equaliser on 77 minutes.
A long throw was nodded on by Cousin and Aubameyang met the ball on the volley and blasted it home from the centre of the penalty area, showing great technique in the process.
And just a minute later it was 2-1. Cousin showed trickery in the box and fired in a low shot that trickled in off the post to send the home fans truly wild. Gabon could have made the game safe when Eric Mouloungui had the goal at his mercy but he blasted the ball over the bar.
It looked as though he would be made to pay when Morocco were awarded a penalty in the final minute of ordinary time after Youssouf Hadji's shot struck the arm of Charly Moussonou. It looked the right decision.
Kharka stepped up to convert the spot kick and at this stage Morocco were still in the competition, just about.
But a reckless challenge from Medhi Benatia in the seventh minute of injury time gave Mbanangoye the chance from the free kick and he struck it perfectly to seal the win, and a first quarter-final showing since 1996.
All that needs to be decided now is who finishes top of Group C, with Gabon set to meet Tunisia in a straight shoot-out for the number one position on Tuesday. Niger and Morocco will meet on the same day to avoid the wooden spoon.