Paulinho headed Brazil into the Confederations Cup final with an 86th minute header last night to give the host nation a 2-1 victory over Uruguay as anti-government protesters clashed with police near the Mineirao Stadium.
With the semi-final heading into extra time, Paulinho rose to meet Neymar's corner and score the winner.
Paulinho and Neymar also combined to play a part in Brazil's opener just before half time after Uruguay striker Diego Forlan's penalty was saved early in the game.
Neymar brought down Paulinho's high ball and, after his initial shot was saved by goalkeeper Fernando Muslera, Fred pounced on the loose ball to score.
Although Edinson Cavani seized on sloppy defending to equalize for Uruguay three minutes into the second half, Brazil fought back to secure victory in the 2014 World Cup warm-up tournament.
Outside the stadium, protesters' anger was directed at the government and police. Inside, the animosity was directed from the start at Uruguay captain Diego Lugano, who enraged Brazil by accusing Neymar of diving on the eve of the match.
The crowd was even more incensed when Lugano won a penalty in the 13th minute, although there was little to dispute David Luiz's tugging of the defender's shirt.
Facing a wall of noise, Forlan struck low and goalkeeper Julio Cesar dived correctly to his left.
It was the fourth penalty out of eight in the tournament so far to be missed.
Forlan, though, was the most potent attacking threat on the pitch as Brazil struggled to impose itself on the South American champions.
The swagger and verve the Brazilians had rediscovered to open the tournament with three group-stage victories was missing in an edgy start by the hosts.
Neymar, on whose shoulders the nation's World Cup hopes are resting, was lacking the service to make an impact.
There was the occasional moment of menace, with Hulk using his strength to burst through the defense, but Uruguay came closer to taking the lead.
Forlan unleashed a curling strike on the half-hour from outside the penalty area which crept wide of the post.
Uruguay's resistance was eventually broken by a deep ball from Paulinho that went high over the defense and reached Neymar.
From a tight angle, Neymar brought the ball down with his chest, and Muslera did well to deny the striker his fourth goal of the tournament.
From the save, the loose ball trickled across the penalty area before reaching Fred. And two defenders proved to be an ineffective barrier, even to a scuffed shot from Fred which landed in the bottom corner of the net.
The relief was clear: Fred jumped over the advertising hoardings to celebrate closer to the Brazil fans who packed the stadium.
Brazil's elation disappeared three minutes into the second half.
Slack defending gifted Uruguay its way back as several chances to clear the danger were wasted. A clearance from Luiz lacked urgency, then Thiago Silva's pass to Marcelo was easily intercepted by Cavani, who scored past Cesar.
However shoddy the work of Brazil's defenders was, the quality of the forward players was starting to shine through as the game became feisty, with five yellow cards awarded.
Brazil pressed and probed for the winner: Fred struck over from Neymar's cross and the star forward had an effort saved himself.
The game was heating up, and Neymar exchanged taunts with Uruguay's Alvaro Gonzalez before sarcastically blowing him a kiss.
But Neymar helped to ensure Brazil had the last say in the match, as he floated a corner into the penalty area that Paulinho rose above Martin Caceres to meet and head into the net.
Brazil will meet Italy or Spain in Sunday's final at the Maracana Stadium in Rio de Janeiro.