On the ground where they suffered the heaviest defeat in their history, Mexico achieved their greatest triumph on Saturday when they denied Brazil the only significant trophy missing from the five-times World Cup winners' collection. Two goals from the 28-year-old centre-forward Oribe Peralta were answered only by a 91st-minute effort from Hulk, although Oscar, who will start the Premier League season with Chelsea, missed a wonderful opportunity to send the final into extra time with only a handful of seconds remaining.

In May 1961 Mexico arrived at Wembley and suffered an 8-0 battering at the hands of the England of Johnny Haynes, Bobby Robson and Bobby Charlton, who scored a hat-trick. On Saturday their fans were setting off a Mexican wave five minutes into the match, in celebration of an opening goal which had come 29 seconds after the kick-off. Never has that usually intrusive and irrelevant ritual seemed more appropriate to the occasion.

Coached by Luis Fernando Tena, Mexico worked hard, took their chances and defended with spirit. Brazil, as so often in recent years under a succession of coaching regimes, glittered with talent but lacked application and method. This was their third defeat in Olympic finals – they lost to France in 1984 and to the Soviet Union in 1988 – and it will be taken seriously back home. It may even cost their head coach, Mano Menezes, his job, since there was little sign on Saturday of progress towards the construction of a side capable of regaining the World Cup on home territory in two years' time.

Once again London did its distinguished visitors proud as the sunshine that bathed Jamaica's sprinters turned up again for the footballers of South and Central America, and for a crowd of 86,162 who had arrived to witness the climax to a tournament that some British commentators had derided as irrelevant. A crowd 80,203 had turned up at the same venue 48 hours earlier to watch an excellent women's final between the United States and Japan, a world record for an Olympic football match featuring female teams. In the group stage almost 77,000 had thought it worth paying to see Gabon versus South Korea.

This tournament has been a triumph, fully worthy of its place in the great international pageant of sport, and if it deserved a better final than it got that was hardly the fault of the winners. Mexico is a country in which the passion for the game runs deep but despite regular qualification for the World Cup – and places in the quarter-finals in 1970 and 1986, when the tournament was held on their home soil – their results have never lived up to that enthusiasm. Before this their only tournament victory had come when they beat Brazil to win Fifa's Confederations Cup, a second-tier tournament, in 1999.

The statue of Bobby Moore overlooking Wembley Way welcomed the teams under a sun as bright as that in Guadalajara when the England captain and Pelé embraced after a wonderful World Cup match in 1970. If there was no evident sign of the greatest Brazilian of them all on Saturday, that may have been something to do with one of his long-standing commercial affiliations: he is a spokesman for Mastercard and, as the Olympic slogan has it "we are proud only to accept Visa".

Mexico, their starting XI consisting entirely of players from clubs in their domestic league, were given a wonderful start in the opening minute after Rafael da Silva, Manchester United's Brazilian right-back, played a loose pass infield and saw Javier Aquino deflect the ball to Peralta, who drove a low, firm right-foot shot inside the near post.

Brazil, whose side were picked from five foreign leagues as well as their own, took 20 minutes to find any sort of pattern at all, though their attacking momentum improved when Hulk came on for Alex Sandro after half an hour. The Porto forward's swerving drive gave José Corona, Mexico's goalkeeper, his first really uncomfortable moment, and Marcelo, the Real Madrid left-back, placed a shot wide after a move involving Oscar and Leandro Damião. When the much-coveted Neymar shot wide moments before the interval, it seemed as though Brazil may be coming to life.

Oscar delivered promising passes for Neymar on a couple of occasions early in the second half but the arrival of Alexandre Pato, the Milan forward, in place of Sandro, Tottenham's defensive midfielder, did little more than make it easier for Peralta to run across the face of goal without obstruction in the 75th minute to meet Marco Fabián's right-wing corner with a firm downward header past Gabriel, Brazil's defenceless goalkeeper.

Another grotesque misjudgment by Rafael in the 84th minute – a misplaced backheel from the touchline inside his own half – brought the defender into a nose-to-nose confrontation with his team-mate Juan Jesus, and a minute later he was making way for Lucas.

Four minutes of time were added on, and in the first of them Hulk chased a long ball before shooting across Corona. When the same player produced an inswinging cross from the right two minutes later, the fate of the gold medal seemed in the balance as Oscar rose alone to meet it at the near post. But the tall, slender £25m 20-year-old could only direct his header wide, sending Brazil home to contemplate what will surely be a difficult and disputatious two years.