A mistake by Manchester United full-back Rafael allowed Oribe Peralta to drill home an early opener after just 28 seconds to leave the Selecao shell-shocked.
Brazil struggled to assert themselves in the game and indeed the best chances fell to Mexico particularly in the second half.
On the hour mark Brazil breathed a sigh of relief when Marco Fabian hit the crossbar, before Peralta had a goal ruled out for offside.
However, Luis Fernando Tena’s men would not be denied and with a little over 15 minutes to go Peralta grabbed his second of the game with a superb header to give them breathing space.
A late strike from substitute Hulk reduced the deficit and Oscar had a glorious chance to equalise in the dying seconds but it was too little, too late as Mexico held on to seal the win and the gold medal.