Egypt scored a 95th-minute penalty to beat Congo 2-1 and so reach the World Cup for the first time in over a quarter of a century.
Mohamed Salah was the Egyptian hero, scoring both goals in a win that qualified them for their third finals – and first since 1990.
Congo’s equaliser two minutes from time, as Arnold Bouka-Moutou thumped home, shocked the hosts in Alexandria.
But the Egyptians’ World Cup hoodoo ended as Salah held his nerve late on.
His dramatic winner sparked wild scenes of celebration both on and off the pitch, as several players and fans took to the field to celebrate while supporters wept with joy in the packed stands.
The Liverpool star had broken the deadlock just after the hour on a tense night in Alexandria as he latched on to Mohamed El Nenny’s pass before poking home from close range.
But an energised stadium was flattened just minutes from full time when Bouka-Moutou ghosted in at the far post to slam a volley home past Egypt goalkeeper Essam El Hadary.
Hopes were raised as five minutes of stoppage time were indicated and in the penultimate of these, Egypt were awarded a penalty.
Salah coolly sent the Congo keeper the wrong way to spark a night of celebrations across Egypt and end the record seven-time African champions’ poor World Cup record.
In the 27 years since their last World Cup appearance, Egypt have won four Africa Cup of Nations titles – in 1998, 2006, 2008 and 2010 – but never taken that form into World Cup qualifying.
They had suffered repeated heart-break instead, with one of the most painful defeats coming in 2009 when losing a bitterly-contested play-off against Algeria.
BBC reports that the desperation to qualify ahead of the game was so great that Egypt’s Argentinian coach Hector Cuper admitted he was taking medication for high blood pressure.
The victory gives Egypt an unassailable four-point lead over Uganda in Group E, with one round of fixtures left.
They become the second African team to reach the finals after Nigeria made it through on Saturday, with the remaining three places to be decided in November.
Earlier this year, the North Africans – whose first World Cup appearance was way back in 1934 – finished runners-up in the Africa Cup of Nations.