Just when Egypt looked capable of achieving what looked a highly unlikely target, they threw away their lead to lose 2-1 at Tunisia and set an unwanted record of failing to reach the African Cup of Nations three times in a row.
The Pharaohs, needing to win by a two-goal margin to qualify for next year's Equatorial Guinea finals as the best third-placed side among the seven groups, went ahead on the quarter-hour mark, thanks to a goal from Mohamed Salah.
The record seven-time winners appeared a much improved version of the one which suffered two defeats by Senegal and lost at home to Tunisia, looking very composed in the first half.
However, once a Hossam Ghaly mistake allowed Tunisia's Yassine Chikhaoui to restore parity seven minutes after the interval, Egypt dramatically collapsed.
The already-qualified Carthage Eagles toyed with Egypt and were unlucky not to score on several occasions until Wqahbi Khazri curled home a late free kick, drawing cheers from the crowd in Monastir.
The third-place ticket went to DR Congo, who defeated Sierra Leone 3-1 in Group D to finish their campaign with nine points.
Egypt also finished third but with just six points, which they had collected from two successive wins over minnows and bottom side Botswana. Tunisia advanced to the Nations Cup as Group G winners, followed by Senegal who crushed Botswana 3-0 on Wednesday.
Egypt have never failed to reach Africa's showpiece three straight times. They missed out on two consecutive editions twice: in 1965 and 1968 and 2012 and 2013.
Coach Shawky Gharib is likely to learn his fate in the coming few days, with the Egyptian Football Association set to hold a board meeting to decide whether to keep faith with him.
A three-man Egypt midfield was well marshaled by the defensive-minded Ahmed Fathi, who closed down spaces in the visitors' own half and allowed Hossam Ghaly and Mohamed Elneny to operate freely in the final third of the pitch.
In an exciting opening, Salah spurned a golden chance to open the scoring as early as the third minute when he ran onto a through ball from Elneny and eluded a tame challenge from goalkeeper Aymen Mathlouthi but his shot from a tight angle hit the side netting.
However, he made amends on 15 minutes after finishing off a neat move involving deep-lying forward Walid Soliman.
With his back to his marker, the Ahly man flicked a pass and looped the ball over the defence and into the path of Salah, who sprang the offside trap and sent a left-foot first-timer past Mathlouthi.
Egypt eased off after going ahead but Tunisia were toothless upfront, with a couple of half-chances doing little to trouble 41-year-old keeper Essam El-Hadary, who looked assured between the sticks after making his first competitive appearance in more than two years following the injury of Ahmed El-Shennawy.
The veteran goalie palmed away a cross-cum-shot from Yassine Chikhaoui and easily handled several crosses while Elneny sent a volley wide at the other end in a half littered with some tough tackles, especially from the Egyptians.
Tunisia looked much livelier in the early stages of the second half, pressing high up the pitch in a strategy that paid off almost immediately.
Central midfielder Hossam Ghaly, one of Egypt's best performers in the first period, gave away possession near his own penalty area and Tunisia pounced to level the score. An initial effort was blocked by left-back Sabri Rahil but Chikhaoui gathered the loose ball and made no mistake with a left-foot shot from inside the area that went into the roof of the net.
Tunisia had complete control following the equaliser, causing constant menace to a shaky backline via repeated crosses from the left and right, one of which picked out Fakhreddine Ben Youssef unmarked but his acrobatic effort missed the target.
Egypt's solitary chance fell to Walid Soliman, who tried to control a low cross from right-back Ahmed Elmohamady with his back to goal but he was too slow to swivel, with Mathlouthi rushing out in a timely manner to collect the ball ahead of him.
Tunisia deservedly netted the winner with nine minutes remaining when Khazri's impressive free-kick sailed over the wall and past the despairing dive of El-Hadary as Egypt were once again left to lick their wounds.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)