Crowds began gathering not long after the Mexican team scored its first goal in the first minute of play, with shouts of "Goal!" ringing out from bars and homes. Fans erupted in massive celebration as the game ended, marking Mexico's first ever Olympic soccer gold medal.
Cheering Mexicans turned the downtowns of Mexico City, Guadalajara and other cities into street parties. Hundreds of fans waving the country's red, white and green flag took a victory lap around the capital's landmark Angel of Independence statue, with traffic shut down on the city's main boulevard.
"Mexico didn't let up in the match," said law student Arturo Castellanos, who watched in Mexico City's chic Condesa neighbourhood. "Even though I was embarrassing myself, I was screaming all kinds of rude things."
Ignacio Villegas, 18, took the risk of wearing Brazil's yellow jersey while walking through the neighbourhood. He said he admired Brazil's style of soccer and his grandfather was Brazilian. But he couldn't help celebrating his country's victory.
"Brazil didn't play as a team although they have nothing but stars," he said. "And Mexico played excellently."
Mexican President Felipe Calderon called the team's coach, Luis Fernando Tena, by telephone to congratulate him on the win.
"I think this is the best period of football that we have had in a long time: two Under-17 championships, the Pan American championship and now the Olympic championship," he told Fernando according to a transcript of the call released by the presidency.
The mood was notably more sombre in Brazil, a country known for its elegant form of soccer but still awaiting its first-ever Olympic gold medal in the sport. Brazil has won more World Cup titles than any other country.
Sadness and frustration were clearly etched on the faces of the nearly 100 beer-drinking fans that packed the Prainha Paulista bar in the country's biggest city, Sao Paulo.
"Brazil played horribly," chemical engineering student Leoncio Martinez said, turning away from the TV screen. "The team deserved to lose, and the Mexicans more than deserved to win."
In Rio de Janeiro, fans in surfer shorts and bikinis gathered on the seaside city's white-sand beaches to watch the game.
People dressed like Brazilian soccer star Neymar posed with other fans to take pictures before the match, while the Beija-Flor samba group's drummers pounded out heavy Carnival rhythms, stoking the festive atmosphere.
The party didn't last long.
Mexico's first goal immediately silenced the crowd and sent the few Mexican fans on the beach into delirium.
Brazilian fan Rosemary de Oliveira put the best face she could on the loss.
"I wanted it to be gold, but it doesn't matter, the most important is to participate," she said after the match. "We won the silver! Go Brazil!"
Associated Press writers Stan Lehman in Sao Paulo and Renata Brito in Rio de Janeiro contributed to this report.