Libya scored an injury-time winner against Rwanda to take them through to the quarter-finals of the African Nations Championship (CHAN) as runners-up in Group C.
Substitute Elmutasem Abushnaf scored the crucial goal after Libya dominated but looked like missing out on the win they needed to advance after squandering chances and hitting the post.
Nigeria came from behind to beat already-eliminated Equatorial Guinea 3-1 to ensure they finished top of the group on seven points.
Nsi Eyama gave Equatorial Guinea an unexpected lead in the 40th minute before Anthony Okpotu’s diving header, Dayo Ojo’s formidable long-range effort and Rabiu Ali’s penalty spot their win.
Libya, the 2014 champions of the tournament for locally based players only, began their match knowing they had to win to make it through to the quarter-finals, while Rwanda knew a draw would suffice for them.
After a poor first-half it was Rwanda who had more of the possession, but Libya who created more chances but neither side managed a shot on goal in the first-half.
Libya continued to pile on the pressure after the break and created several good chances to score with Abdulrahman Khalifta managing to fire over the bar from six yards out and then Ahmed Eltrbi bundling the ball onto the post in the 85th minute.
The winner eventually came in injury time when a neat back-heel from Saleh Tader, who scored two goals in the win over Equatorial Guinea, found Bader Ahmed and his deflected cross was put into the net by Abushnaf to the delight of his team-mates and many inside the Grande Stade de Tanger.
In the other Group C game Nigeria had to come from behind to win against Equatorial Guinea.
Eyama headed home the opening goal in the 40th minute as he connected with a corner from Miguel Ngomo.
The local Super Eagles fought back after the break as Okpotu met a cross from Osas Okoro with a diving header to equalise.
Nigeria took the lead thanks to a spectacular strike from Ojo from outside the area on the left flew across the goal into the top right-hand corner.
The win was sealed by Ali’s spot-kick after Okpotu had been fouled in the area.