Libya scored three minutes into stoppage time to edge Rwanda 1-0 Tuesday and snatch an African Nations Championship (CHAN) quarter-finals place behind Group C winners Nigeria.
Relentless Libyan pressure in northern Moroccan city Tangiers finally paid off when substitute Elmutasem Abushnaf swept a low cross into the roof of the net.
Nigeria topped the table with seven points, Libya had six, Rwanda four and Equatorial Guinea finished pointless.
But justice was done when dominant Libya scored and they will travel south to Agadir and prepare for a last-eight showdown Sunday against the Group D winners, currently Congo Brazzaville.
Nigeria got a fright before beating Equatorial Guinea 3-1 in Atlantic city Agadir with 37-year-old Rabiu Ali wrapping up the victory by converting an 83rd-minute penalty.
Ekundayo Ojo put the Nigerians ahead on 69 minutes with a candidate for the best goal of the tournament as his thunderbolt shot from outside the box flew into the net.
As Equatorial Guinea faded, Nigeria stretched the lead when Ali — the second oldest player at the tournament after 38-year-old Congo goalkeeper Barel Mouko — netted.
Nigeria return to Tangiers for a quarter-final against the Group D runners-up, a position Angola occupy ahead of a Wednesday clash with Congo.
Although the biennial Nations Championship is restricted to home-based footballers, matches carry full international status and count toward the monthly FIFA rankings.