A brace from Al Busaifi Ihaab was not enough to send Libya through to the knockout stages of the African Nations Cup.
Marcos Paqueta's men needed to win their Group A game and hope Equatorial Guinea would beat Zambia and, although Ihaab's double ensured they kept their side of the bargain, Zambia's 1-0 win ensured it was nothing more than a proud farewell for Libya.
They and Senegal - who equalised on the night through Deme N'Diaye - are both now out, with much-fancied Senegal ending without picking up a single point.
Knowing that they needed to first and foremost take care of their own result, Libya started well and got off to the perfect start, opening the scoring in the fifth minute.
A jinking run from Admed Saad created some space and, after he played a reverse pass, Ihaab was on hand to do the rest from just inside the area.
The lead was shortlived, though, with N'Diaye getting ahead of his front-post marker to nod home Mamadou Niang's ninth-minute corner.
Niang himself then blazed over from distance, with Jamal Mohamed doing the same at the other end, before Senegal's Souleymane Camara saw his close-range hit brilliantly kept out by Samir Abod.
Camara was making a real nuisance of himself and his cross then found Pape Malickou Diakhate, but his header was well saved by Abod.
That was the last meaningful action of the first half and the last real incident until the hour mark, which saw Ahmed Zuway's strike blocked by Kader Mangane as Libya hunted a second.
That could have come when Mohamed El Moghrabi's corner found Abdalah Al Sherif, only for him to miss the target, before Mangane got in the way of another Zuway effort.
Newcastle-bound Papiss Cisse then swung a shot over the bar, before Ali Samala went close to scoring for Libya; his header being kept out by Khadim N'Diaye.
A second Libyan goal did arrive, though, and when it did, with six minutes remaining, it was a memorable one.
Zuway cushioned a long ball into the path of the onrushing Ihaab and he spectacularly volleyed it into the bottom corner.
Cisse tried his best to get Senegal level for a second time just after, but time was not on their side as Libya held on.