Brazil denied the United States a shock victory by coming back from two goals down to win the Confederations Cup.
A Clint Dempsey flick and a Landon Donovan strike on the counter put the US into a surprise 2-0 half-time lead.
Luis Fabiano pulled one back for Brazil before Kaka was denied an equaliser when his header was wrongly judged not to have crossed the line.
Luis Fabiano's headed second levelled matters before, five minutes from time, Lucio nodded in a corner to win it.
After upsetting the odds so spectacularly with their 2-0 semi-final victory over Spain, the US almost tore up the script again, against opponents who had beaten them 3-0 in the group stage of the competition.
Predictably, favourites Brazil had the lion's share of possession, but the incisive football was played by the American underdogs throughout the first half.
Indeed, with their first attack the US scored.
Jonathan Spector launched a cross from deep at Dempsey, whose swinging volley made the faintest of touches to direct the ball past Julio Cesar.
Even at such an early stage, it was clear that Brazil were waiting for one of their leading lights to create something from nothing as opposed to taking collective responsibility.
Three times their star-turn Kaka created chances for others, firstly Robinho, then Felipe Melo and finally Maicon, but each time American goalkeeper Tim Howard was equal to the final shot.
After 25 minutes, Brazil were made to pay for their profligacy as the USA launched a superb counter-attack which resulted in a superb second goal.
Donovan found Charlie Davies on the left wing, whose incisive return pass found Donovan in space and bearing down on goal but still with plenty to do.
The striker's touch took him away from the covering Ramires and his next touch was a perfectly placed side-foot shot past Cesar.
With seconds remaining in the half Brazil almost clawed back what would have been a barely merited goal when Maicon got round the back of the American defence, but his cross was deflected away from the lurking Fabiano by Carlos Bocanegra.
Barely a minute into the second half, the dynamic of the game changed as Felipe Melo fed Luis Fabiano, who swivelled sharply and shot past Howard.
With the momentum now in their favour, Brazil attacked with regularity and were mistakenly denied parity on the hour as Kaka's far post header from an Andre Santos cross was pushed clear by Howard, but replays showed that the ball had crossed the line.
Luis Fabiano had a chance to equalise when he was played in on goal by substitute Elano - and played onside by Oguchi Onyewu - but Howard was quick off his line to smother the ball before the striker could shoot.
With 15 minutes to go Luis Fabiano did pull his side level.
Kaka drove in from the left and crossed for Robinho whose shot hit the underside of the bar but bounced nicely for Luis Fabiano who made no mistake in nodding the ball past the diving Howard.
With Brazil now in the ascendancy, the US were unable to hold out, and five minutes from time the turnaround was complete.
Elano's outswinging corner was met by the unmarked Lucio and his powerful header struck the inside of Howard's right-hand post on its way in to break American hearts.
US coach Bob Bradley:
"That defeat really hurt.
"I'm extremely proud of my players, but it still feels pretty lousy to let this one get away.
"I hope though that people around the world see we have good team and great players and it is a big step forward."
Brazil coach Dunga:
"Even after we went 2-0 down the team was still sure of itself. We told them at half-time to play down the wings, keep patient.
"We did that, we have been together for 29 days and we were determined to win it.
"It is very difficult to overcome a 2-0 deficit, it is not easy, but if you have committed players who never give up then you have a chance and we came back in the second half. We showed a high level of professionalism."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.