Defender Daniel Alves was sent off just before half-time after his foul on Javier Hernandez in the box earned him a second yellow card.
However, Mexico failed to add to their early lead after an own goal by defender David Luiz with Jefferson saving Andres Guardado's penalty.
Ronaldinho equalised when he found the top corner with a shot in the 79th minute and defender Marcelo hit the winner five minutes later after a one-two with Neymar.
It was Mexico's first defeat in 15 matches under coach Jose Manuel de la Torre, though their under-23 side lost three matches at the Copa America in July under assistant coach Luis Fernando Tena.
There was a massive police presence at the match after a shooting incident outside the ground at a league match in August.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.