LONDON (AP) — Leandro Barbosa scored 10 of his 23 points in the final six minutes, rallying Brazil to an 88-82 win over Spain in the preliminary round finale in the men's Olympic basketball tournament for two medal contenders who could eventually challenge the Americans for gold.

Barbosa scored 20 points in the second half for Brazil (4-1), which trailed by 10 early in the fourth quarter. But the super-speedy Barbosa, who now plays for the Toronto Raptors, made a pair of 3-pointers and four free throws in a 12-2 run.

Pau Gasol scored 25 points and his brother, Marc, added 20 for Spain (3-2), which may have actually gained something by losing.

The Spaniards are assured of not playing the U.S. (4-0) until the gold-medal game — if they and the Americans continue to advance and both get back to the Olympic final again. The U.S. beat Spain for gold at the 2008 Beijing Games.

The U.S. played Argentina in the late game, which would decide the seeding in the quarterfinals.

Pau Gasol said he's not concerned about who Spain meets next.

"The way we're playing right now, anybody could beat us," he said. "Right now it's not happening for us."

Brazil, which would face Argentina on Wednesday if the U.S. wins as expected Monday night, played without 6-foot-11 starting center Nene. He sat out with foot soreness.

Nene, traded to the Washington Wizards last season, has been bothered by plantar fasciitis and Brazil decided to rest him for the upcoming medal round.

Leading into the game, there had questions whether Spain or Brazil might sit players and not try to win to avoid facing the U.S. until there was gold up for grabs. Eight badminton players were recently expelled from the London Games for trying to lose and the IOC is keeping a close eye to ensure the Olympic creed "to have fought well" is upheld.

Spain guard Jose Calderon dismissed the notion the Spaniards might have tried to intentionally lose.

"No, never," he said. "This is not our team, this is not the way we play, this is not the way. We've been together since I don't know how many years and we always play to win. Always."

The Brazilians sure did.

They trailed 67-57 early in the fourth quarter, but began chipping into Spain's double-digit lead while the bearded Gasol brothers sat on the bench.

Barbosa made two free throws to pull Brazil within 73-69, and then hit consecutive 3-pointers to put his country ahead 75-73 with 4:16 remaining. Marc Gasol fed his brother in the lane for a nice basket underneath, and Pau Gasol hit a free throw on Spain's next trip to make it 79-76.

But after Anderson Varejao's free throw, Barbosa got behind Spain's defense and scored an easy layup to give Brazil an 82-76 lead.

Spain got within five points but was sloppy in the final two minutes and suffered its second straight defeat in pool play after losing to Group B winner Russia on Saturday.

Among the 12,000 fans watching in the first half was the U.S. team. LeBron James and his teammates sat in the stands and took mental notes before playing rival Argentina in their final game before the quarters. The Americans beat both Brazil and Argentina in an exhibition tour leading up to London.

With no Nene to contend with down low, Pau Gasol dominated inside in the early going, scoring 13 of Spain's first 18 points as the defending silver medalists opened a 26-17 lead after one.

The Los Angeles Lakers star sat out the first 6:07 of the second quarter, but had an impact as soon as he came back with a three-point play to put Spain ahead 40-35. Gasol finished the first half with 16 points.