Peralta struck after just 30 seconds and the Mexican striker sealed one of the all-time great Olympic upsets when he scored again late in the second half.
Hulk got one back in stoppage-time but Mexico, playing in their first Olympic final, were deserved winners as Brazil once again failed to end their long wait for a first football gold.
While Brazil have graced the World Cup with some of the best players and most dazzling performances ever seen on football’s grandest stage, the Selecao have never managed to replicate those golden moments at the Games and this was another miserable chapter in their Olympic history.
Brazil, bronze medallists in Beijing in 2008, lost in the Olympic final in 1984 and 1988 and their failure to win gold has rankled with such a proud football nation for decades.
Mano Menezes’s team are unlikely to get a sympathetic reception on their return home after such a lacklustre display riddled with nerves and defensive blunders.
“You can see by the look on my face what my feelings are. It’s not difficult to guess. I’m very sad we did not win,” Menezes said.
“If you lose you feel under dark skies and that was the mood I left behind in the dressing room.
“We did excellent work throughout the tournament and believed we had a very good chance of getting gold, but it was not to be.”
Mexico manager Luis Fernando Tena added: “We are extremely happy. It’s a wonderful moment for our country. Mexico will be on the streets partying right now.
“It’s a great moment for a coach to see his players singing the national anthem with gold medals around their necks.”
Mexico had won three of their past five matches against Brazil, including a 2-0 friendly victory in June, and there was no sign of an inferiority complex as Tena’s side made an astonishing start.
Just 30 seconds had been played when Manchester United right-back Rafael da Silva dwelt on the ball and then poked a hesitant pass towards Sandro, who was caught flat-footed as Javier Aquino stole possession.
Peralta latched onto Aquino’s pass and the Santos Laguna striker advanced unchecked before slipping a clever low shot past Brazil goalkeeper Gabriel from just outside the penalty area.
Brazil seemed shell-shocked by such a disastrous opening. It took 21 minutes for Brazil’s first shot on target and Menezes was growing increasingly frustrated on the touchline.
By the 32nd minute he had seen enough and hauled off Alex Sandro, with Porto striker Hulk sent on.
That at least gave Brazil a brief spark and defender Marcelo slashed wide after Oscar’s flick gave him a sight of goal, then Hulk surged forward and forced Jose Corona to parry his long-range strike.
Leandro Damiao was quickly onto the rebound, but Corona recovered his footing to block the striker’s follow-up.
Brazil needed more from Neymar in the second half but the Santos striker’s composure deserted him when he lashed a good chance high over the bar.
Marco Fabian should have made Neymar pay for that miss when the Mexico midfielder harried Juan Jesus out of possession. But Gabriel blocked Fabian’s first shot and from the rebound the Mexican’s overhead kick looped onto the crossbar.
Moments later Peralta saw his shot ruled out for offside, but Brazil’s defensive frailties were exposed again in the 75th minute.
When a free-kick was curled over from the right, Peralta was granted the freedom of the penalty area to power home a header that left Brazil exchanging angry recriminations.
Hulk gave them hope of a dramatic late fight-back when he burst through to drive a low shot under Corona in the first minute of stoppage-time.
And incredibly Oscar should have forced extra-time, but the Chelsea midfielder headed over with the goal at his mercy as Mexico held on.