Oribe Peralta wrote his name into Mexican folklore with a deadly double against the five-time world champions, who many believed were destined finally to end their agonising wait for Olympic Games glory.
Despite Hulk pulling a goal back in stoppage time and Chelsea new boy Oscar missing a last-gasp chance, Brazil were a shadow of the attacking force that had smashed in 15 goals en route to the final.
The game promised to be a goal-fest, with Brazil having scored three times in all five of their matches and their opponents netting seven in their last two.
But few would have predicted the fastest goal ever in a FIFA tournament final after just 28 seconds.
Manchester United right-back Rafael's pass was intercepted by Javier Aquino and the ball broke for Peralta to race goal-ward unchallenged and fire home.
It was not the first time Brazil had been behind at London 2012 and they might have levelled in the 13th minute when Thiago Silva headed Neymar's free-kick over.
Oscar also should have done better than find Jose Corona when he was allowed to turn and shoot eight yards out.
Brazil's sloppiness continued as they found it hard to penetrate a fiercely-committed opposition and made poor decisions when they did.
They made an attacking change just past the half-hour mark when midfielder Alex Sandro was withdrawn for Porto team-mate Hulk.
And the substitute almost caught out Corona with a piledriver from nearly 35 yards but the goalkeeper recovered well to foil Leandro Damiao's rebound. Marcelo should have tested him again when he flashed wide from Damiao's lay-off.
Hulk was making a real impact, winning a free-kick that Romulo ultimately glanced wide in first-half stoppage time.
The urgency Brazil had been lacking arrived straight from the restart and Neymar was so close to sending a screamer into the top corner.
Mexico's response to the threat was to send on Miguel Ponce for Aquino.
Santos star Neymar skied a good chance when the ball fell to him 10 yards out but Mexico weathered the storm and were unlucky not to double their lead in the 64th minute after another defensive mistake.
Marco Fabian tackled Thiago Silva and although Gabriel came rushing out, his save set up an overhead kick Fabian smashed against the crossbar.
Leandro Damiao had a good chance nicked off his toe and powered a free header wide from a corner before Peralta rightly had a second goal ruled out for offside.
Fabian almost scored when he nodded over Jorge Enriquez's flick-on from a corner but made amends 15 minutes from time with a free-kick that Peralta netted with a bullet header.
Brazil should have staged an amazing comeback in stoppage time, Hulk racing on to a long ball from Marcelo and rifling into the net, before crossing for an unmarked Oscar to somehow nod wide from six yards.