The game appeared to be on its way to an uneventful conclusion but in the fifth minute of added-on time, Salem Al-Dawsari found the bottom corner from eight yards to give his nation their first win on the global stage since 1994.
While Saudi Arabia finish in third place in the group, Egypt end the tournament without a point and have not registered a victory at this competition in seven attempts.
Both teams went into this fixture with little to play for but it did not take long for the game to click into gear with Saudi Arabia firing a number of efforts from distance off target.
Moments later, Salah should have doubled his tally after being played through on goal for a second time but the forward tried to be too clever and flicked the ball well wide of the far post.
Egypt continued to push for a second and Trezeguet twice went close with curling efforts but Saudi Arabia ended the first half on top and were awarded a penalty when Ahmed Fathy was deemed to have stopped a cross with his hand.
Goalkeeper Essam El-Hadary - who had become the oldest player to feature at a World Cup at the age of 45 - pulled off a stunning stop, tipping the ball onto the underside of the crossbar, but Saudi Arabia were given another opportunity from 12 yards when Ahmed Hegazi was harshly adjudged to have committed the slightest of shirt pulls on Fahad Al-Muwallad inside the penalty area.
Even with the use of VAR and having the opportunity to view the incident himself, the referee stuck with his original decision and Salman Al-Faraj made no mistake as he swept the ball into the left-hand corner.
After the restart, the intensity of the game dropped but Hattan Bahebri almost put Saudi Arabia into the lead with a volley from an acute angle, only to see his strike go just over the bar.
Back up the other end, Trezeguet got on the end of an inswinging cross delivered to the back post, but the Egypt winger could only head marginally wide of the far post.
As the game entered the final quarter, Housain Al-Mogahwi was given the chance to score his first international goal at the back post but the midfielder's header was tipped over the crossbar by El-Hadary.
Both teams appeared to have settled for a point apiece by the time four minutes of added-on time were signalled, but a neat move from Saudi Arabia was allowed to continue into a fifth minute and it was finished off by Salem Al-Dawsari, who volleyed into the bottom corner from an acute angle.
SAUDI ARABIA (4-5-1): Al Mosailem; Os.Hawsawi, Alburayk, Om.Hawsawi, Al Sharahni; Al Faraj, Al Dawsari, Otayf, Al Mohqawi, Bahbri (Assiri 65'); Al Muwallad (Al-Shehri 79')
EGYPT (4-5-1): El-Hadary; Fathy, Gabr, Hegazy, Abdelshafy; Trezeguet (Kahraba 81'), Hamed, Elneny, Said (Warda 46'), Salah; Mohsen (Sobhi 64')