Bruno Zita Mbanangoye netted a brilliant last-minute free-kick to earn African Nations Cup co-hosts Gabon a stunning 3-2 victory over Morocco and a place in the quarter-finals while dumping their opponents out.
In a frantic finale, Gabon had looked to have claimed the win as two goals in three minutes late on through Pierre-Emerick Aubameyang and Daniel Cousin saw them overturn a first-half deficit to lead 2-1 heading into injury time.
However, Morocco captain Houssine Kharja, who had earlier given his side a 24th-minute advantage, coolly rolled home a 90th-minute penalty to level up the scores and seemingly earn his side a vital draw.
There was still one late twist though as deep into stoppage time Gabon earned a free-kick to the left of the area and Mbanangoye stepped up to curl a superb effort inside the near top corner and send the home fans wild.
The result means Gabon and Tunisia - who beat Niger 2-1 earlier on Friday - are through to the last eight after winning both of their Group C matches so far, while Morocco and Niger bid an early farewell.
Substitute Issam Jemaa struck a last-gasp winner to give Tunisia their victory.
Tunisia took a fourth-minute lead through the impressive Youssef Msakni but Niger equalised four minutes later in controversial fashion when William N'Gounou netted following a possible handball from his team-mate Ouwo Moussa Maazou.
Both teams created a host of chances after that, including each hitting the woodwork, but it was Tunisia who claimed the points when Jemaa netted in the 90th minute.