Mexico upset Brazil 1-0 to extend their unbeaten record to 19 and reach the semi-finals of the Confederations Cup in Hanover.
Mexico have won both their group games
Jared Borgetti, who missed a penalty in the first half despite taking it three times, nodded in after 59 minutes.
Brazil's Adriano headed home a Kaka cross nine minutes later but was it was ruled offside.
Brazil face Japan on Wednesday to decide who will take the other semi-final place from Group B.
The first-half penalty was awarded after 30 minutes when Borgetti was brought down by Brazil captain Roque Junior in the box.
Borgetti put the spot-kick into the back of Dida's net but Italian referee Roberto Rosetti made him take it again after spotting Jose Fonseca enter the penalty area before the kick was taken.
Borgetti's second attempt hit the crossbar but the 31-year-old striker was handed a third chance, this time after Brazil's Emerson had encroached into the box.
Borgetti then saw Dida save that kick but the Mexican had the last laugh with his second-half winner.