The Japanese men looked set to join their women's team in setting up a gold medal match at London 2012 when a superb third goal of the tournament from Yuki Otsu gave them an early lead in Tuesday afternoon's semi-final.
But Marco Fabian, Oribe Peralta and substitute Javier Cortes turned the game around as Mexico set up a final on Saturday against Brazil or South Korea and left their opponents playing for bronze.
Neither side had previously competed for gold and each had made the Olympic semis for only the second time, having last done so in 1968 when Japan went on to beat host nation Mexico in the bronze-medal match.
And despite some nervy defending early on, the Japanese were on course to emulate that result after 12 minutes on Tuesday thanks to a stunning strike from Otsu.
Mexico goalkeeper Jose Corona, who had already tipped a Hiroshi Kiyotake 25-yarder wide, was helpless as Otsu's instant control from Keigo Higashi's pass set up a 20-yard half-volley the forward crashed into the top corner.
It was the first time the Central Americans had trailed at the Olympics and they now needed to become the first side to score against Japan.
Fabian scuffed his finish after some slack defending and Giovani dos Santos drilled wide when the ball fell to him from a blocked shot.
The pressure told in the 31st minute when Dos Santos' corner was flicked on by Jorge Enriquez and Fabian nodded home from close range.
Neither side could force a second before half-time, after which the game got increasingly tetchy, Hiroki Sakai eventually booked for a foul on Fabian.
Mexico continued to call the shots and completed their comeback in the 65th minute with a goal that was both sublime and ridiculous.
Peralta had just drilled too close to Shuichi Gonda, who rolled the ball out to Takahiro Ohgihara.
But the midfielder dallied and was robbed by Peralta, the striker still having plenty to do as he drove an unstoppable strike right into the top corner.
Ohgihara almost made amends with a free-kick that was met by a looping backheader from Kensuke Nagai and was tipped over by a backpedalling Corona.
Japan threw on Kenyu Sugimoto, Takashi Usami and Manabu Saito but they were unable to find a way through and were overcommitted in the final minute of stoppage-time as Cortes held off several weak challenges before firing the ball under Gonda.