With them finishing third in Group B instead, Spain avoided an early meeting with powerhouse USA and the soonest they can meet is in the gold-medal match, while Brazil finished second with win, which put them in a possible semifinals duel with the mighty Americans.
Leading by nine points and looked to be headed to their fourth win in five games, Spain had a late-game collapse, while Brazil suddenly got into their groove.
Led by Leandrinho Barbosa, Brazil slowly chipped into the Spaniards’ lead and Barbosa caught fire, scoring 10-straight points to turn give Brazil a two-point lead with 3:47 left in the game.
From then on, the Brazilian squad never looked back and withstood comeback attempts from the Spanish squad en route to the upset victory.
Barbosa finished with 23 points on 8-for-13 shooting from the field, while Marcus Vieira and Tiago Splitter added 13 and 11 points, respectively, for Brazil, who finished the preliminary round with a 4-1 record.
Pau Gasol, on the other hand, had 25 points and seven rebounds, Marc Gasol added 20, while Serge Ibaka finished with 14 points and six rebounds to go with three blocks for Spain, who lost to Russia in their previous game.