Belo Horizonte -- Paulinho scored an 87th-minute winner as Brazil defeated Uruguay 2-1 to earn a place in the Confederations Cup final here on Wednesday.
The Corinthians midfielder met a Neymar corner-kick with a powerful header at the far post that left goalkeeper Fernando Muslera with no chance.
Earlier, Uruguay striker Edinson Cavani had cancelled out Fred's first-half strike while Diego Forlan missed a penalty for the Celeste.
The hosts will meet the winner of Thursday's match between Spain and Italy in the final at Rio de Janeiro's Maracana stadium on Sunday.
Brazil coach Luiz Felipe Scolari could barely contain his emotion after the victory in front of more than 60,000 fans at the Mineirao stadium.
"This is one of the most exciting games I have been involved in for a decade," said Scolari, who led Brazil to victory at the 2002 World Cup during his first spell in charge.
"The fans were crucial today. It was due to them that we were able to overcome all the difficulties. They carried us over the line."
Forlan scuppered a chance to give Uruguay the lead in the 15th minute when his penalty attempt was saved by Julio Cesar after David Luiz brought down Diego Lugano in the area.
Brazil midfielder Luiz Gustavo was lucky to escape with just a yellow card following a reckless studs-up challenge that left Cristian Rodriguez clutching his abdomen.
Uruguay were unable to convert their superiority onto the scoresheet and paid the price on the stroke of half-time.
Neymar opened up Uruguay's defence when he controlled Paulinho's lofted pass with his chest before his shot was smothered by Muslera. Fluminense forward Fred then pounced to fire in the rebound - his 42nd goal from 48 appearances at the Mineirao.
However Uruguay were not to be denied. Napoli striker Edinson Cavani netted two minutes after the restart by drilling in a low shot after an errant Thiago Silva pass.
But Brazil regained the momentum, and Paulinho sent the crowd into ecstasy with his fifth goal from 15 international matches.