Raul Ruidiaz delivered the knockout blow after the Peru star punched the ball into the back of the net to seal a humiliating elimination for the Selecao.
After Andy Polo zipped down the right wing in the 75th minute and cut the ball across, substitute Ruidiaz bundled it home and wheeled off to celebrate, while Brazil started protesting furiously to referee Andres Cunha and his linesman.
The official ruled the goal out, with Peru joining in the furious debate, which lasted for over two minutes, with the referee taking instructions over his earpiece from a mystery third party.
Eventually he awarded the goal - implying that whoever he was speaking to was not watching a video replay - because if they had it would have been an easy decision to rule it out.
Peru’s victory saw them top Group B to set up a quarterfinal clash with Colombia, while Ecuador go through second and Brazil finish a humiliating third.
Ruidiaz claims his controversial goal against Brazil was legal because the ball hit him on the thigh, despite replays clearly showing he punched it into the net.
He says: “It was a quick move and it hit me in the thigh. I don’t understand why there was controversy, because it was a clean play.”
Some have compared it to Diego Maradona’s “Hand of God” goal and Ruidiaz did say Peru’s victory was thanks to God, although he did not make specific reference to his goal.
Brazil’s Dani Alves says the handball is not a get-out clause for his team’s knockout.
Alves says: “‘I believe it does not serve as an excuse. It is a fact that Brazil has achieved nothing in our last major competitions, and against that there are no arguments.
“I am very competitive, so going through this is unacceptable to me as a competitor.”
Meanwhile, USA and Colombia have qualified from Group A, with Mexico and Venzuela already having qualified for the playoffs in Group C, despite still having to play a game.
Group D will be decided early tomorrow morning, with leaders Argentina facing bottom-placed Bolivia, while Chile and Panama will go head-to-head in a straight shootout for a spot in the playoffs.