Nigeria beat Equatorial Guinea 3-1 in Agadir to top African Nations Championship Group C and advance to the quarter finals alongside Libya, who struck in second-half stoppage time to take Rwanda's place in the final eight.
Salisu Yusuf's side top the group on seven points after second-half goals from Anthony Okpotu, Dayo Ojo and substitute Rabiu Ali overturned Equatorial Guinea's first-half advantage, while Libya advance alongside them on six points after Elmutasem Abushnaf struck in the 93rd minute.
Rwanda head home with four points, and Equatorial Guinea end their campaign pointless, despite some bright moments against Nigeria.
The Super Eagles haven't convinced in their first two fixtures - being held by Rwanda before narrowly beating a lethargic Libya team - and they fell behind after 40 minutes when Nsi Eyama headed past Ikechukwu Ezenwa at a corner.
However, after another unconvincing first-half performance - with Sunday Faleye firing wide with the goal at his mercy after snatching the ball from Okpotu in the 42nd minute - they responded in style after the break.
Okpotu cut a frustrated figure in his first two matches at the CHAN, but he demonstrated his poacher's instincts to head home at the back post in the 59th minute following a fine cross from the impressive Osas Okoro.
10 minutes later, Nigeria had taken the advantage after Ojo - installed to the starting lineup at the expense of Ali - slammed home a powerful right-footed effort from outside the area.
Seven minutes from time, Ali - introduced to prove some late experience after replacing Ifeanyi Ifeanyi - made sure of the victory from the penalty spot after Okpotu had been fouled in the box.
Over in Tanger, Libya left it late but ultimately secured progression at the death after Abushnaf finally ended Rwanda's resolve following a well worked moved down the Amavubi's right.
Up to that point, it looked like Antoine Hey's side would get away with a draw despite a negative display.
13 minutes from time, Abdulrahman Rahamdhan Khalifa fired over from close range as the Rwanda failed to clear their lines from a corner, while Ahmed El Trbi hit the post at the death after being picked out - unmarked - at the back post.