Mexico were leading 2-0 into stoppage time, which, coupled with Poland's defeat to group winners Argentina by the same scoreline, meant the two teams would have finished level on points, goal difference, goals scored, goals conceded and head-to-head record, having drawn their opening group game 0-0.
But with Poland having a narrow edge on fair play points, Mexico had to continue to pour men forward in search of a goal to send them to the knockout stage. And in doing so, they were caught on the break by Saudi Arabia, meaning Poland advanced by one goal (0 GD for Poland, -1 for Mexico).
For Mexico, it is the first time they will not feature in the World Cup knockout stage since 1990, when they were banned from the tournament. The last time El Tri qualified for the tournament and failed to make it out of the group stage was in 1978.
Mexico's chances of progressing had looked slim going into the match after taking one point from their opening two matches and needing a big win and/or help from Argentina or Poland in the other game to advance.
Urgently needing to beef up their goal difference, Mexico took the game to Saudi Arabia from the start Wednesday at Lusail Iconic Stadium and never stopped running, peppering the goal with long-range efforts in a desperate bid to wrest control of their own fate.
After going goalless through their first 2½ matches and 430 minutes in total at the World Cup dating back to 2018, Mexico exploded to life in spectacular fashion to start the second half.
Henry Martin finally broke the deadlock in the 47th minute, finishing from close range after Cesar Montes flicked on a corner to give Mexico hope.
Just five minutes later there was pandemonium. From almost 35 yards out, Luis Chavez sent a free kick arrowing into the top corner to put Mexico 2-0 up and within sight of the knockout stage.
When Argentina soon went 2-0 up on Poland, Mexico needed just one more goal to progress.
Repeatedly they came agonizingly close to to achieving it. Hirving Lozano found the net but saw the goal ruled out for offside. Then Martin should have scored but volleyed over the bar with just the goalkeeper to beat, immediately dropping his head into his hands.
More pain was to follow when substitute Uriel Antuna broke clear behind the Saudi defense and applied the finish, but again the offside flag went up.
And as Mexico continued to desperately surge forward through seven minutes of stoppage time, Saudi Arabia broke and delivered the final blow to El Tri's hopes thanks to Salem al-Dawsari's goal.
Information from Reuters was used in this report.