"We are very pleased with the win and we know what an outstanding team Spain is," US coach Mike Krzyzewski said after the Americans completed a sweep of their five warm-up games before opening the defence of their Olympic title.
The US team beat Spain in the gold medal final at the 2008 Beijing Games but a rash of injuries to some of their tallest players has since raised concerns about how they would fare against a bigger Spanish squad.
Spain used their edge in height to their advantage in the first quarter of Tuesday's game opening the floor with their passing and getting the ball down low to Serge Ibaka and Pau Gasol, who roamed the paint with impunity.
The home favourites ran off 10 consecutive points for a 10-3 lead to the delight of the Palau Sant Jordi crowd and pushed to a 22-13 advantage before Anthony and his team mates clawed their way back, cutting the margin to 23-21 by the end of the quarter.
Anthony, who came off the bench to score 10 points to slow the Spanish surge, continued his hot hand in the second quarter as the US team turned up the defensive pressure to force turnovers and find the New York Knicks forward for open shots.
He sank a trio of three-pointers and tallied 13 points in the period to lift the reigning Olympic champions to a 48-40 lead at intermission, while he and James did yeoman's work on defense neutralising Spain's towering frontcourt.
"Carmelo was sensational and his play was the difference in the game," said Krzyzewski.
The Americans expanded the lead to 14 points after three quarters, having forced seven turnovers by the Spaniards in both the second and third quarters, and turned the game into a rout as both sides became content to hoist long jumpers at the end.
Anthony had a game-high 27 points, while James contributed 25 points, 14 of them in the fourth quarter, and eight assists.
James and Anthony did extra duty as the final line of defense as US centre Tyson Chandler got into foul trouble in the third quarter and fouled out early in the fourth quarter.
"They came out with a lot of intensity," Anthony said. "Once we just settled down and got into our comfort zone we never looked back."
Los Angeles Lakers 7-foot (2.13 m) forward Gasol, whose 7-foot-1 (2.16 m) brother Marc of the Memphis Grizzlies did not play due to an injured left shoulder, led Spain with 19 points with Oklahoma City Thunder's Ibaka scoring 16 points.
"We would have liked to play better and commit fewer errors," Pau Gasol said. "It was impossible to wrest control of the game back. We made too many mistakes and they capitalized.
"Other than that, it was positive because we got a clear idea of the hypothetical match-up in London. Marc is a very important part of the team and can be decisive in a game."
The men's Olympic basketball tournament begins Sunday, with the United States playing France, and Spain going against China.