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 takes them to the tournament for the first time since 1990 at the expense of Ghana.
Congo's equaliser four minutes from time, as Arnold Bouka thumped home, had dampened spirits in Alexandria.
But the Egyptians' World Cup hoodoo ended as Salah held his nerve late on to convert the spot kick.
More than 80,000 supporters at Borg El-Arab erupted into ecstasy when Salah broke the deadlock three minutes past the hour mark as Egypt looked close to realizing a long-held dream, having made the last of their two World Cup appearances 27 years ago in Italy.
However, the atmosphere was subdued and many fans shed tears when Congo's Arnold Bouka equalized with a half-volley after a defensive lapse with three minutes remaining.
With the clock ticking down in stoppage time and a victory desperately required, Salah invoked memories of Emad Meteb's famous last-gasp header against Algeria in 2009 when he sent the keeper the wrong way from the spot after substitute Mahmoud Trezeguet was hauled down in the area.
After years of underachievement on the international level, Egypt were finally given something to cheer about after reaching next year's Russia finals with one match to spare in Group E.
They remained on top of the group with 12 points, gaining an unassailable four-point lead over Uganda. They face Ghana next month in a meaningless match in Kumasi.