A brace from Al Busaifi Ihaab was not enough to send Libya through to the knockout stages of the CAF Africa Cup of Nations.
Marcos Paqueta's men needed not only to win their Group A game, but also needed Equatorial Guinea to defeat Zambia. And, although Ihaab's double ensured they kept their side of the bargain in a 2-1 victory, Zambia's 1-0 win over the co-hosts ensured it was nothing more than a proud farewell for Libya.
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 short lived, 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 shot brilliantly kept out by Samir Abod.
Camara was proving to be a real nuisance for the Zambian defence 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.