Brazil scraped into the final of the Confederations Cup with victory in an emotional and highly-charged encounter at the Estadio Mineirao.
Paulinho's late header ensured the Selecao finally saw off a resilient Uruguay to set up a clash with Spain or Italy in the Maracana in Rio de Janeiro on Sunday.
Fred had given Brazil a scarcely-deserved first-half lead, prodding home Neymar's cross. But Uruguay hit back shortly after the interval when Edinson Cavani capitalised on an error from Brazil captain Thiago Silva to strike a low shot beyond Julio Cesar.
Home goalkeeper Cesar had earlier saved Diego Forlan's first-half penalty, after David Luiz pulled down Uruguay captain Diego Lugano.
This was a test of character and spirit for Luiz Felipe Scolari's Brazil but the jubilation among the players and coaching staff at the final whistle showed just how much this meant. Brazil never approached their fluent best but they did just enough to get over the line.
The build-up had been every bit as passionate and spiky as the game itself. Cesar had described the rivalry between the nations as more intense than that of Brazil's with Argentina, while Uruguay captain Diego Lugano had accused Neymar of attempting to fool referees by diving.
But for all the talk, on both sides, of a fiesta of South American football, the match was fraught and fractious. Neither side found their fluency, as Uruguay drained the game of pace and momentum, quietening the crowd and adding to the mood of tension around the ground.
But it was an incident in the 14th minute, involving two players who had featured in the build-up, that changed the mood. Uruguay won a corner and as the players jostled in the penalty area, Luiz grabbed a handful of Lugano's shirt and the Uruguay captain went to ground for a penalty.
The Brazil players surrounded Chilean referee Enrique Osses and the stadium erupted in fury. Forlan was made to wait and wait to take the spot-kick and his effort was low and tame, allowing Cesar to dive to his left and turn the ball behind with a flick of his glove.
The noise that rumbled around the Estadio Mineirao initially appeared to shake Brazil from their slumber. And yet for the remainder of the half, they looked a side lacking cohesion, confidence and sustained threat - insipid not inventive.
Uruguay continued to threaten, frustrating Brazil, snapping in tackles and denying them space. Rodriguez headed just over while Forlan fizzed a curling left foot shot just wide.
It seemed it might take a mistake, some individualism or a piece of good fortune to break the deadlock and give Brazil hope - so it proved.
With half-time in sight, Paulinho's lofted pass spun perfectly into the path of Neymar. He forced the ball back across goal, but it was deflected into the path of Fred, via a deflection off Lugano, allowing the local boy to force the ball into the net with his shin.
And yet Brazil were still prone to lapses in concentration. With the second half just minutes old, their captain Thiago Silva ended a calamitous series of errors by passing the ball to Cavani in the penalty area. The highly-rated Napoli striker fired a low shot beyond Cesar before many Brazilians had taken their seats, to level the game and stun Estadio Mineirao into silence for a second time.
The introduction of home-town hero Bernard lifted the home crowd once more. His quick feet took him past two Uruguay defenders within minutes of his arrival only for Fred to fire high and wide when the ball finally came his way.
Uruguay dropped deeper and deeper as Brazil went to the flanks in search of an opening. Cavani, though, still threatened. One shot deflected narrowly wide, but with time running out it was the hosts who struck the decisive blow. Neymar floated a corner over from the left and Paulinho rose highest to head in at the far post and spark scenes of jubilation.
Brazil coach Luiz Felipe Scolari:
"If you keep plugging away something good will happen and that happened today.
"Four wins in four games is important. We are on the right track."
Uruguay manager Oscar Tabarez:
"More than having an effect on my team, the penalty miss had a huge effect on the opponent.
"They had been second best until then and from that moment they grew."