Javier Hernandez came off the bench to help Mexico reach the last 16 of the World Cup with a 3-1 win over Croatia to emerge from Group A as runners-up behind Brazil.
Mexico, who will face Group B winners Netherlands in the knockout phase, had looked happy to hold out for the draw that would have got them through, before the Manchester United forward came on to turn the match on its head.
Within 10 minutes of Hernandez entering, Rafael Marquez put Mexico ahead with a powerful header, before Andres Guardado rounded off a swift counter attack and Hernandez himself finished with a close-range header.
Mexico briefly flirted with top spot in the group, needing one more goal to depose Brazil before the tournament hosts got a fourth against Cameroon.
Ivan Perisic then grabbed a late consolation for Croatia who had substitute Ante Rebic sent off in the dying stages for a studs up challenge.
Mexico, securing a sixth successive appearance in the second round, finished second in the group with seven points, behind Brazil on goal difference after the hosts beat Cameroon 4-1.