A superb individual goal from Jesus Manuel Corona was enough for Mexico to secure top spot in their Copa America group as they drew 1-1 with Venezuela.
They had appeared to be heading for defeat after falling behind to defender Jose Manuel Velazquez's overhead kick 10 minutes into the match in Houston.
That was after Mexican manager Juan Carlos Osorio had left most of his first-choice players on the bench ahead of the quarter-finals given they only needed a point to secure first place in their section.
Substitute Corona spared his blushes as he picked up the ball around 40 yards from goal before bursting forward, beating five men and showing great footwork to finish with 10 minutes left.
Corona's goal meant the sides finished on seven points each, with the 2001 runners-up having a greater goal difference.
Mexico consequently face defending champions Chile next in the last eight, while Venezuela's failure to get past their opponents in the standings means they will take on Argentina.
Before kick-off there was a minute's silence in memory of the people who died at the weekend in the nightclub shooting in Orlando.
The Mexicans went into the game having won their last 11 fixtures but that run came to an end, with Osorio defending his decision to rotate his team afterwards.
He said: "Rotation is part of life when you have a squad of players, We give opportunities to all players because we believe that they are all important. We selected a good group to compete against Venezuela."
Mexico seemed for so long to be heading for a quarter-final clash with the Argentines as they fell behind then struggled to draw level with a team who had knocked out Uruguay in their last game.
The Venezuelan goal came when Alejandro Guerra swung a curling free-kick into the box and Christian Santos rose at the far post to head back across the face of goal.
Velazquez was falling away but twisted his body acrobatically to hook in a wonderful volley that flew into the roof of the net past Mexico goalkeeper Leobardo Lopez.
Mexico dominated the rest of the first half but were unable to find a breakthrough as their makeshift starting line-up struggled to gel.
Venezuela were lucky not to concede a penalty when Wilker Angel looked to have handled in the area after Hector Moreno's header.
Mexico looked galvanised after the break, with Corona shooting wide and Jesus Molina doing the same soon after.
Venezuela squandered a good chance to go 2-0 up when substitute Josef Martinez went clean through only to shoot tamely at Corona and that was the cue for Corona's incredible equaliser.
In the group's other match, Uruguay finished their tournament with a 3-0 victory over Jamaica in Santa Clara.
They went ahead through Abel Hernandez in the 21st minute, doubled their lead on a Je-Vaughn Watson own goal in the 66th minute then sealed victory through Mathias Corujo.
The result meant Jamaica signed off having lost all three of their games in the USA without scoring a single goal.