Mano Menezes's men started the second half brightly. Hulk and Neymar were a constant threat, but resilient Mexican defending restricted them to long-range efforts.
Mexico barely entered their opponents' half in the opening stages of the second period, but they almost doubled their lead on the hour mark against the run of play and soon found momentum.
Fabian did will to get the better of Silva for a clear shot on goal, although he watched his acrobatic effort come back off the crossbar.
The midfielder had another chance to double Mexico's lead 10 minutes later when he jumped up in the box unmarked for a free header, but he put it into the stand.
Brazil began to fall apart, and when they let their guard down on 75 minutes, Peralta punished them again. The big striker took advantage of sloppy defending to head past a helpless Gabriel to make it 2-0.
Hulk pulled a goal back for Brazil with one of the final kicks of the ball to make for a nervy finish, and Oscar almost capped off an unbelievable comeback with a late header, only to miss from point-blank range.
The Porto forward's late strike proved little more than consolation in the end, and the favourites had to settle for silver.