Cannot play media. Sorry, this media is not available in your territory.
Video - USA win basketball gold
The United States men's basketball team regained the Olympic title, but they were made to work for a 118-107 victory by a valiant Spain side.
Reigning world champions Spain provided a genuine challenge in a classic game with Rudy Fernandez, who scored 22 points, in inspirational form.
Spain got to within two points late on but the US had an extra gear and made the most of their free-throw chances.
Earlier, Argentina earned a consolation bronze with a 87-75 win over Lithuania.
The US side - nicknamed the Redeem Team in a reference to the 1992 Dream Team that first included professional players - had beaten Argentina in cruising through to the final and demolished Spain 119-82 in the preliminary rounds.
But, under the gaze of the watching David Beckham, they were made to exert themselves in order to make up for the embarrassment of slumping to bronze in the 2004 Games.
"What you saw today was a team," said American star Kobe Bryant. "Everyone talks about 'arrogant' NBA players but what you saw was us facing adversity and bonding together.
"This is more important and more special than any championship that any of us will ever win."
And LeBron James added: "USA is back on top again. Respect to Spain, they were unbelievable. We had a game plan and they countered with incredible plays.
We played with great character in one of the great games in international basketball history
"The game was never over. I'm watching the game all over again in my head. It will go down in history as one of the greatest."
Fernandez sank a three-pointer with 8:13 remaining in the final quarter to pull Spain just two points behind at 91-89, and Pau Gasol hauled them back to 104-99 and 108-104 as the clock ticked down.
A steady flow of points from Dwyane Wade (27) and Bryant (20) ensured the US always kept their noses in front.
And some Spanish naivety in defence, after Fernandez had been fouled out, gave their opponents to set the seal on things with a string of free throws as the gold medal returned to the home of the NBA for the 13th time.
US coach Mike Krzyzewski added: "I'm proud of our guys. We played with great character in one of the great games in international basketball history."
In the bronze-medal match, Chicago's Carlos Delfino led the way with 20 points for Argentina, who were without top scorer Manu Ginobili because of an ankle injury.
A third-quarter dunk from forward Andres Nocioni gave the South Americans a 20-point lead.
And Lithuania, who beat Argentina by four points in the group stage, could not haul the deficit back in time.
Ginobili had been the tournament's leading scorer before he twisted his ankle and Delfino dedicated the victory to the inspirational San Antonio Spurs guard.
"We wanted to win this for Manu," said Delfino. "He tried to warm up for this game but he was in too much pain.
"It's fantastic to win bronze. This team has incredible heart."