(CNN) -- Five-time world champions Brazil needed to come from two goals down to beat underdogs the United States 3-2 in the final of the Confederations Cup in South Africa on Sunday night.

Brazil celebrated a third Confederations Cup triumph following victories in 2005 and 1997.

Captain Lucio headed an 84th-minute winner to end the hopes of the plucky Americans, who scored twice in the first half-hour in Johannesburg.

Clint Dempsey, who netted in the shock 2-0 win against European champions Spain in the semi-finals, put the U.S. ahead in the 10th minute.

A massive upset seemed to be on the cards when captain Landon Donovan doubled the lead in the 27th minute, but Brazil reduced the deficit just 41 seconds after the half-time break through Luis Fabiano.

The striker then leveled with his fifth goal of the tournament in the 74th minute before Lucio rose highest to ensure that Brazil retained the title.

Brazil went into the game seeking a massive improvement on their dismal showing in laboring to beat hosts South Africa 1-0 in the semi-finals.

But Bob Bradley's U.S. team, beaten 3-0 by Brazil in the group stage, took a shock lead when Dempsey found space in the penalty area to guide home Jonathan Spector's fierce right-wing cross for his third goal of the tournament.

Don't Miss

Goalkeeper Tim Howard continued his fine form to keep the Brazilians at bay, then Donovan finished off a superb counter-attack that the South Americans would have been proud of.

The veteran, who earlier in the tournament said his worst footballing memory was a 7-0 drubbing by Brazil when playing for the U.S. under-23 side, set the speedy Charlie Davies free down the left. He then controlled the return pass to cut inside Ramires and slot past Julio Cesar -- extending his national goalscoring record to 41.

Howard then saved a low angled shot from Fabiano, then the Sevilla forward headed over the bar 10 minutes before the interval.

But Fabiano struck a killer blow soon after the restart when otherwise-impressive U.S. defender Jay DeMerit allowed him to collect Kaka's pass inside the penalty area and swivel to fire past a helpless Howard.

Brazil surged forward in search of an equalizer, and Real Madrid's new signing Kaka thought he'd scored it when Howard beat out his downward header via the underside of the crossbar while the Everton keeper appeared to be behind the line.

However, the referee ruled otherwise to the Brazilian's disgust, which seemed to be justified by television replays.

Howard denied Fabiano when clear through on goal in the 70th minute, but soon after the forward was on hand to poach the leveler. Kaka beat full-back Spector down the left and his low cross was deflected into the path of Robinho, who prodded the ball against the underside of the bar -- and Fabiano headed home the rebound.

With the Americans visibly tiring, it was no surprise when Brazil claimed the winner.

Lucio found space in the box to powerfully head a corner from second-half substitute Elano into the net off the left-hand upright, with the U.S. defense having crucially left the post unguarded.

It was Brazil's third Confederations Cup triumph, having also won in 1997, and represented a 14th victory in the last 15 meetings with the U.S.

Coach Dunga has now presided over seven wins in 20 days, with five at the Confederations Cup and two in World Cup qualifiers.