The west Africans leave the tournament in shame as they lose their third game to the north Africans, who also fail to progress to the last eight
Libya defeated Senegal 2-1 when they met in their final Group A encounter in the 2012 Africa Cup of Nations on Sunday night in Bata.
However, the two teams have now been eliminated from the competition.
Libya needed a win along with the hope that Zambia would lose in the other encounter against co-hosts Equatorial Guinea in Malabo.
On the other hand, the Teranga Lions, who had lost both of their previous games, were looking to save face before going back home by earning at least a point.
Ihab Albusaifi struck for the Mediterranean Knights on five minutes after forward Ahmed Saad won a tackle and dribbled past four defenders before setting up his team-mate, who slotted through the legs of goalkeeper Khadim Ndiaye.
The Lions then stepped up their game as Deme Ndiaye nodded home a Mamadou Niang corner kick on 11 minutes to restore parity.
Substitute Papiss Cisse had an opportunity to send the Senegalese clear but his lobbed kick over the Libyan goalkeeper Samir Aboud went wide of the intended target.
The Mediterranean Knights nicked the winner on 84 minutes when Albusaifi rose to nod home a cross to consign the west Africans to their third successive defeat of the competition.
Any hope held by the Libyans of qualifying for the knockout stages were quashed when Zambia took the lead in their game against Equatorial Guinea thanks to captain Christopher Katongo.