Salem Al Dawsari struck an injury-time winner as Saudi Arabia recorded their first World Cup win since 1994 by beating Mohamed Salah's Egypt 2-1.
Reports of Salah quitting international football dominated the build-up to this dead rubber in Group A but he briefly set the speculation to one side by opening the scoring with his second goal of the competition.
The Pharaohs ended a miserable tournament pointless, though, after a controversial penalty from Salman Al Faraj and Al Dawsari's dramatic late strike turned the game around.
The two teams came into their final group game having already been eliminated from the competition following defeats to Uruguay and hosts Russia.
Liverpool forward Salah initially appeared to have been left out of his country's starting line-up before a team-sheet mistake was quickly corrected.
The 25-year-old's relationship with the Egyptian FA was strained leading up to the tournament due to a sponsorship row taking focus away from preparations, while he is reportedly disappointed at how he has been used for political gain by administrators.
Recent criticism received after he was pictured with controversial Chechen leader Ramzan Kadyrov, accused of numerous human rights violations, has apparently only contributed to the player's unhappiness.
He soon underlined his importance on the pitch though, calmly lifting the ball over advancing goalkeeper Yasser Al Mosailem in the 22nd minute after latching on to a raking pass forward.
It was Egypt's first goal from open play at a World Cup since 1934 and Salah, who converted a penalty against Russia in their second group game, should have doubled the advantage minutes later.
He broke clear on goal but, after drawing Al Mosailem, uncharacteristically dinked wide of the right-hand post.
Saudi Arabia, whose last World Cup win came 12 games and 24 years ago, worked their way back into the contest and were presented with a golden chance to level when referee Wilmar Roldan awarded them a penalty after penalising Ahmed Fathy for handball.
Fahad Al Muwallad took the spot-kick but his powerful effort was tipped onto the crossbar by Egypt's 45-year-old goalkeeper Essam El Hadary - the oldest player to appear at a World Cup.
Juan Antonio Pizzi's side were soon given a chance to make amends, in contentious circumstances.
Colombian official Roldan adjudged Egypt defender Ali Gabr had impeded Al Muwallad inside the box in first-half added time and awarded a second spot-kick.
The two players appeared to have hold of each other but, after taking more than three minutes to consult VAR and watch replays of the incident, Roldan stuck with his initial decision, allowing Al Faraj to send El Hadary the wrong way from 18 yards.
The second half was a far more tight affair and looked set to end in stalemate until Al Dawsari drove home with the last kick of the game to leave Egypt pointless and bottom of Group A.
GOAALLL! Salah races through and lobs the goalkeeper to put Egypt ahead against Saudi Arabia.#KSAEGY #WorldCup #EGY pic.twitter.com/g5dV3s1YY4
— ITV Football (@itvfootball) June 25, 2018
PENALTY SAVED! A record-breaker and now a spot-kick saved by Essam Elhadary to keep Egypt ahead against Saudi Arabia.#WorldCup #EGY #KSA #KSAEGY pic.twitter.com/B7Qow5T7ur
— ITV Football (@itvfootball) June 25, 2018
GOAALLL! Saudi Arabia get back on level terms, Alfaraj burying the penalty to make it 1-1 against Egypt after a lengthy VAR review.#WorldCup #EGY #KSAEGY #KSA pic.twitter.com/rD1NFPDS2V
— ITV Football (@itvfootball) June 25, 2018
GOAALLL! Saudi Arabia steal a last-gasp win with a fine finish from Salem Aldawsari!#WorldCup #KSAEGY #KSA pic.twitter.com/ASjdtju1Gc
— ITV Football (@itvfootball) June 25, 2018