Japan had a goal ruled out for offside inside 10 minutes when Yasuhito Endo’s shot struck Shinji Okazaki but it was Mexico who missed the half’s golden opportunity when Andres Guardado headed against the post when completely unmarked in the area.
Mexico flew out at the start of the second half, creating numerous opportunities, and deservedly took the lead when Guardado’s superb cross was met by the onrushing Hernandez before the Manchester United striker doubled the lead with a header at the back post.
Japan pulled themselves back into it when Okazaki’s strike bounced off the bar and over the line before more late drama when Hernandez was fouled in the area. However, the striker’s injury-time penalty was saved and he lashed the rebound against the crossbar.
Neither side could reach the semi-finals prior to kick-off, with Brazil and Italy both qualifying from Group A.
The Japanese drew plaudits for their fearless display of attacking football, albeit coupled with defensive fragility, against the Italians in their last encounter and started with a similar intensity as they probed the Mexican backline.
Their first chance came when the two Shinji’s, Okazaki and Kagawa, combined with the latter poking straight at Guillermo Ochoa when well placed.
And they thought they had taken the lead soon after when chaos in the Mexican area afforded Endo a strike at goal but his effort flicked the toes of Okazaki on the way through causing the linesman’s flag to shoot up.
The half then descended into a series of niggling fouls as both sides struggled to keep possession before it belatedly burst into life in the final five minutes as Guardado inexplicably headed against the post when free, Okazaki almost wriggled clear to shoot in the Mexican area and Eiji Kawashima flapped a powerful Jesus Zavala effort wide.
Mexico started the second half in impressive fashion and carved out two early opportunities as first Giovani Dos Santos cut inside and saw his fierce effort headed behind before Raul Jimenez nodded straight at Kawashima from the resulting corner.
But it didn’t take long for them to seize the advantage as Guardado worked some space down the left and delivered a teasing cross towards Hernandez who headed home from close range.
Dos Santos then almost doubled the lead when his half volley was tipped onto the post by Kawashima before Japan forged a chance of their own when Ryoichi Maeda cut inside and flashed a shot into the side netting.
Mexico grabbed their second soon after, aided by desperate Japanese defending from a corner, as Hiram Meir’s flick on was met by the head of Hernandez at the back post.
The Central Americans nearly grabbed a third when Dos Santos cut inside again, this time unleashing a strike which Kawashima turned wide as they sought to put the game beyond doubt.
Japan reduced the arrears with five minutes to play when Endo knocked the ball across for Okazaki to score via the bar to create a pulsating finish to the second half.
They threw players forward in a desperate attempt to get level but were made to pay when a swift Mexico counter led to Hernandez being fouled by substitute Atsuto Uchida inside the penalty area.
The Manchester United striker dusted himself down to take the spot kick but Kawashima flung himself to his right to save before the Mexican fired the rebound against the crossbar.
Mexico held on to claim an impressive win which hands them a much needed confidence boost ahead of their four crucial World Cup qualifiers in the autumn.
MAN OF THE MATCH
Giovani Dos Santos (Mexico) - Was pivotal in much of Mexico’s good work after coming alive in the second half.
JAPAN: Kawashima 5, Kurihara 5, H.Sakai 6, Konno 5, Nagatomo 6, Endo 7, Hosogai 6, Honda 6, Kagawa 7, Okazaki 7, Maeda 6. Subs: Uchida 4, Yoshida 6, Nakamura 6.
MEXICO: Ochoa 6, Mier 7, Reyes 6, Moreno 6, Torres Nilo 6, Torrado 6, Zavala 6, Guardado 7, Dos Santos 8, Jimenez 7, Hernandez 8. Subs: Salcido 6, Barrera 6, Aquino 6.