Japan 1-2 Mexico
Two second-half headers by Javier Hernandez saw Mexico depart the Confederations Cup on a winning note as Japan finished bottom of Group A.
Andres Guardado, who headed against the woodwork, provided the cross which saw Hernandez open the scoring after a fine run by the Manchester United man.
Both teams were already eliminated, but Mexico sealed the win when Hernandez scored from Giovani Dos Santos' corner.
Shinji Okazaki scored a consolation before Hernandez missed a late penalty.
Hernandez was hauled down by substitute Atsuto Uchida before the 25-year-old got to his feet to take the spot-kick which was kept out by Eiji Kawashima.
In a dramatic finale, the ball rebounded back to Hernandez who missed out on a hat-trick by blazing his second attempt against the bar.
However, the miss did not prove costly as Mexico finished third behind Brazil and Italy in the four-team group.
The only consolation for Japan, who return home with no points from three games, is that they know they will be returning to Brazil in 12 months' time after confirming their place at the 2014 World Cup finals as Asian Group B winners.
Whether Mexico will be back remains to be seen.
They still have plenty of work ahead to qualify for the World Cup, but coach Jose Manuel de la Torre will be buoyed by his team's performance against Japan after back-to-back defeats by Italy and Brazil.
There was no sign of what was to come as Japan created a number of early chances.
Manchester United's Shinji Kagawa should have scored his second goal of the tournament before Yasuhito Endo's long-range attempt found the Mexican net via a deflection off team-mate Okazaki.
But the goal was ruled out as Okazaki was offside. Okazaki, who plays his club football in Germany for Stuttgart, then went close after a determined run before Keisuke Honda forced a save from Guillermo Ochoa.
Japan's wasteful finishing proved their downfall.
Mexico went closest to scoring before the break when Guardado's flying 40th-minute header rebounded off the woodwork.
But they secured victory with two goals in 12 minutes after the interval through Hernandez, who now has 35 international goals in 53 appearances.
His first came after a well-timed run to meet Guardado's 54th-minute pin-point cross.
The second was from close range, the striker rising to meet Mier's flick on following a 66th-minute corner.
Japan set up a thrilling finish when Okazaki scored from close range with four minutes remaining after Endo's ball across the six-yard box.
But the drama was not over as Hernandez won and then missed a penalty in Estadio Mineirao.
- 01 Kawashima
- 05 Nagatomo (Nakamura - 77' )
- 15 Konno
- 16 Kurihara
- 21 Sakai Booked (Uchida - 58' )
- 04 Honda
- 07 Endo
- 10 Kagawa
- 13 Hosogai
- 09 Okazaki
- 18 Maeda (Yoshida - 64' )
- 12 Nishikawa
- 23 Gonda
- 02 Inoha
- 03 Sakai
- 06 Uchida
- 22 Yoshida
- 08 Kiyotake
- 14 Nakamura
- 19 Inui
- 20 Takahashi
- 11 Havenaar
- 01 Ochoa Booked
- 04 Reyes
- 15 Moreno
- 20 Torres
- 21 Mier
- 06 Torrado
- 17 Zavala
- 18 Guardado (Salcido - 71' )
- 10 Giovani (Barrera - 77' )
- 14 Hernandez
- 19 Jimenez (Aquino - 90' )
- 12 Corona
- 23 Talavera
- 02 Rodriguez
- 03 Salcido
- 13 Meza
- 22 Flores
- 05 Molina
- 07 Barrera
- 08 Reyna
- 11 Aquino
- 16 Herrera
- 09 De Nigris