Nigeria came from a goal down to smash past Equatorial Guinea 3-1 and win 2018 CHAN Group C with Libya runners-up courtesy of a last-gasp winner against a resolute Rwanda.
The home-based Eagles topped the standings with seven points from three matches, while Libya joined them in the last-eight on six points on the back of a dramatic stoppage time winner.
Rwanda recorded four points with Equatorial Guinea pointless after losing all three games.
Nigeria will face the second-placed team in Group D, which is likely to be Angola, while Libya could tackle Congo, who look set to win Group D.
Nigeria fell behind to an Nse Enyama header on 40 minutes.
But they proved their class after the break when striker Anthony Okpotu restored parity with a clinical header in the 59th minute.
Dayo Ojo, who was handed his first start of the tournament, fired home a rocket from outside the box in the 69th minute for Nigeria to go in front for the first time of the night.
Substitute Rabiu Ali made it 3-1 on 83 minutes from the penalty spot after Okpotu was clattered into by the Guinean defenders.
Libya match winner Sunday Faleye fluffed the best Nigeria chance just before the halftime break when he latched on to a ball controlled by Okpotu as Nigeria chased the game.
Eagles starting XI 4-3-3 vs Eq.Guinea – Ikechukwu Ezenwa (Skipper) – Osas Okoro, Daniel Itodo, Stephen Eze, Kalu Orji – Emeka Atuloma, Ifeanyi Ifeanyi (rabiu Ali 61), Dayo Ojo – Emeka Ogbugh (Mohammed Nur 76) – Anthony Okpotu (Gabriel Okechukwu 84), Sunday Faleye
Coach: Salisu Yusuf