Gabon joined Morocco in the Round of 16 of the Africa Cup of Nations from their pool after the two teams draw 2-2 at Ahmadou Ahidjo Stadium in Yaounde.
Morocco had to come back from behind twice, first through substitute Sofiane Boufal’s 74th-minute penalty which cancelled out Jim Allevinah’s 21st-minute strike for Gabon.
Achraf Hakimi then salvaged a point for the Atlas Lions six minutes from full-time after the Panthers had reclaimed their lead via Nayef Aguerd’s own goal on 81 minutes.
The result saw Gabon settling for a Group C runners-up spot to progress to the next round with two points fewer than leaders Morocco, who have seven.
Both teams proceed to the last 16 unbeaten so far to leave Ghana and Comoros going home.
Morocco coach Vahid Halilhodzic started goalkeeper Munir Mohamedi, replacing Sevilla number one goalkeeper Yassine Bounou.
At the other end, AmaZulu gloveman Jean-Noel Amonome guarded goal for the Panthers for the third game in this tournament while forward Denis Bouanga was out with Covid-19.
Again, the absence of Arsenal forward Pierre-Emerick Aubameyang and Mario Lemina could not be felt as Gabon cruised to the next round.
In the early stages, neither team threatened the goal and the first real chance at goal came 15 minutes into the contest when Ayoub El Kaabi was a bit slow to connect to a Youssef En-Nesyri low cross from the left.
Allevinah then thrust Gabon ahead, connecting first-time with Amonome’s goal-kick after profiting from Nayef Aguerd's error, who slipped while attempting to clear the ball.
Seconds earlier, Ayoub El Kaabi had forced a fine save from Amonome with a low drive.
Allevinah’s goal, which was his second of the tournament, appeared to trigger Morocco’s response and seven minutes later Soufiane Chakla headed narrowly wide off a corner kick.
It was a period of intense exchanges between the two teams as Gabon also came so close to doubling their advantage on the half-hour mark.
Boupendza had turned two Morocco defenders only to face Mohamedi but his effort sailed just wide.
The Atlas Lions coach Halilhodzic then reacted from the bench by pulling out defensive midfielder Sofyan Amrabat for Selim Amallah on 38 minutes.
But the Panthers continued to press and came close again to grab a second goal but Guelor Kanga’s blistering effort from a freekick was brilliantly saved by Mohamedi.
Seconds later, Mohamedi was again called to action to impressively repel number Lloyd Palun’s headed effort off a freekick to complete a series of Gabon’s serious attacks just before the break.
The North Africans attempted to claw their way back into the game in the opening minute of the second half but Amonome stretched well to deny Faycal Fajr’s grounder.
Gabon showed that they were not yet done and 10 minutes into the second period, Allevinah almost grabbed a brace but his shot went just wide with only Mohamedi to beat.
Allevinah was back again on 58 minutes and but witnessed his volley crash against the crossbar.
Shortly after, Morocco thought they had equalised through Hakimi but the goal was ruled offside after consulting VAR.
The pressure from Morocco became relentless and Gabon captain Bruno Ecuele Manga almost converted into his own net but Palun cleared the danger.
As they kept on pressing for an equaliser, Morocco were then awarded a penalty after Andre Biyogo Poko and Amonome were adjudged to have combined to foul substitute Boufal inside the box.
Former Southampton midfielder Boufal then made no mistake to beat Amonome from the spot for his second goal of the tournament.
A moment later in the 76th minute, Aaron Boupendza then closely missed target from a tight angle as Gabon sought to reclaim the lead.
Allevinah then turned provider, crossing for Boupendza whose pressure saw Aguerd beating his own goalkeeper Mohamed to give Gabon the lead again.
The contest became dramatic with Hakimi getting Morocco level again three minutes later after he beat Amonome with a freekick.