Al Bouseffi scored the winner six minutes from time with a fine volley to give Libya their first win in 30 years at the Nations Cup finals.
But it was not enough to get them into the quarter-finals as they finished below Zambia who beat already-qualified co-hosts Equatorial Guinea 1-0 in Malabo on Sunday to top Group A.
Zambia finished with seven points from three games ahead of Equatorial Guinea on six and Libya with four.
Senegal limped out of the tournament having lost all three group matches despite being highly fancied before the start.
Already eliminated before Sunday's match and making five changes from their last game, Senegal were hoping to exit with a positive performance but their crisis of confidence continued in the Equatorial Guinean town.
Playing on a surface cut up by two matches on Wednesday after a heavy torrential downpour, Libya took the lead after just four minutes through Al Bouseffi who shot through the legs of goalkeeper Khadim Ndiaye.
But it was an advantage that lasted just five minutes before slack marking at a corner allowed Senegal's Ndiaye Dembe Ndiaye to equalise with a header.
Libya's Mohamed Esnani cleared off the line from a Mamadou Niang header and their 39-year-old goalkeeper Samir Aboud, who said before the match he was playing his last game, made a low diving save to deny Souleymane Camara in the first half.
Senegal sought to boost their attack after the interval by bringing on Papiss Demba Cisse for his new Newcastle United team-mate Demba Ba and later fellow striker Moussa Sow, who made a surprise return hours before kick-off after travelling to Turkey by private jet to sign for Fenerbahce.
But Cisse could only conjure up a long-range chip over the onrushing keeper that went over the bar.
Libya's win was their first at the tournament since they reached the final of the 1982 edition which they hosted.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.