Paulinho's late header fired Brazil into the final of the Confederations Cup in a hard-fought game with Uruguay.
The scores were level with five minutes remaining with extra-time on the cards, but the Brazil midfielder produced the goods after an all-round average performance from the home side against one of their closest rivals.
Fred opened the scoring three minutes before the break to put Brazil ahead after Diego Forlan had missed a penalty for Uruguay.
Edinson Cavani then equalised early in the second half, thanks in part to some woeful Brazilian defence, before Paulinho sealed a place in the final where they will face either Italy or Spain on Sunday.
It was a below-par performance, especially from Brazil in the first period, and Uruguay will be left to rue a missed opportunity from Forlan from the spot.
Chilean referee Enrique Osses awarded a penalty to Uruguay after Brazil defender David Luiz tussled with Diego Lugano in the box.
Forlan stepped up to face Julio Cesar and the goalkeeper dived to his left and tipped the ball around the post.
Both sides struggled to find their fluency but there were glimmers from Brazil as Hulk barged his way through the Uruguay defence just before the half-hour mark, only to fire his shot over the bar.
Forlan then tried his luck from range at the other end, taking the ball before swivelling and releasing the trigger, leaving striker Luis Suarez cutting a frustrated figure in the area as he called out for the pass.
Brazil then started to press, with Neymar racing down the left and opening up for Hulk in the centre, but the Uruguay defence held firm.
Tempers then started to fray with Brazil's Luis Gustavo shown a yellow card to a high follow through as the local derby threatened to bubble over.
The home side, however, then seized the advantage, with star man Neymar unsurprisingly at the heart of the action.
A long ball allowed the 21-year-old to break into the box, where he took it on his chest and got a shot away which was saved by Fernando Muslera, only for Fred to see home the rebound in what was a welcome breakthrough after a difficult first period.
However, the lead was short-lived as Cavani scored three minutes into the second half for Uruguay after Brazil wasted four chances to clear the ball.
It was a bolt from the blue, especially as Cavani had failed to impose himself in the game, but he snuck in to equalise after Thiago Silva tried to play a square pass to Marcelo, allowing him to tackle the Brazil full-back and scuff a shot past Cesar.
Forlan almost put Uruguay ahead with a header from a free-kick but this time the Brazil goalkeeper was able to palm the ball over for a corner, which came to nothing, while Cavani had another shot blocked in the 79th minute.
However, it was Brazil who had the final word as Paulinho headed them into the final from Neymar's corner with less than five minutes on the clock.