Ihaab Boussefi's two goals were not enough to send Libya through to the quarter-finals at the Africa Cup of Nations despite a 2-1 win over Senegal on Sunday.
Boussefi struck in the fifth and 84th minutes to give Libya victory at the Estadio de Bata but Zambia's 1-0 win over the co-hosts Equatorial Guinea in Group A's other game in Malabo – which was played at the same time – saw the Zambians progress.
The striker's double did give Libya their first victory at the Cup of Nations in 30 years, however, and the country's first win in the competition on foreign soil.
Libya reached the final of the African Cup at home in 1982, then had two defeats and a draw at their only other appearance six years ago.
Boussefi's early goal raised hopes of an unlikely quarter-final place for Libya, who needed a win combined with a defeat for Zambia to have any chance. He finished neatly after being set up by Ahmed Sa'ad.
Deme Ndiaye equalised with a glancing header from a corner in the 11th minute for Senegal, who were playing for pride alone after defeats in their opening two games.
Boussefi claimed a late winner with a sweetly struck volley six minutes from time but Zambia progressed as group winners ahead of Equatorial Guinea, who had already qualified.
The Libyans still go home with a win from a tournament they were never expected to reach after they emerged from chaos and civil war at home during the qualifying competition to make the finals.
For Senegal it was a third straight defeat at the tournament and a humiliating end to their Cup of Nations after being tipped as possible contenders. They lost all three games by 2-1 to exit the tournament without a point for the first time in their history.