LONDON -- Russia pulled out a big win over Spain and also avoided a potential matchup with the heavily favored United States until the gold medal game.
Timofey Mozgov made the tiebreaking dunk with 18 seconds left, Vitaliy Fridzon scored 24 points and unbeaten Russia edged Spain 77-74 on Saturday to take first place in Group B of the Olympic men's basketball tournament.
Russia now could play the U.S. -- if the Americans win Group A as expected and both teams advance in the medal round -- in a rematch of the 1972 title game.
Fridzon, the hero of Russia's victory over Brazil on Thursday, made the clinching free throws with 4.8 seconds left after the Russians had charged back from an 18-point deficit.
Anton Ponkrashov scored 14 points and Mozgov had 12 for the Russians, down 20-2 in the first quarter and still trailing by nine with under 4½ minutes left.
Pau Gasol scored 20 points for Spain (3-1), but missed the first of two free throws with 5.2 seconds left and the Spaniards trailing by two.
Gasol had 11 points in the first quarter, matching Russia's total in Spain's overpowering start. But the Russians pulled into lead in the third quarter, then had one final rally when they appeared out of it again in the fourth.
The Spaniards, the reigning silver medalists, lost to a team other than the U.S. in the Olympics for the first time since 2000 and now risk having to meet the Americans in the semifinals.
Russia tied it at 73 on Victor Khryapa's 3-pointer with 1:01 left, then took the lead when Spain somehow lost Mozgov and he was alone under the basket for a dunk. Gasol missed his first free throw with a chance to tie it, and after Fridzon's two free throws, the Spaniards couldn't get a tying 3-point attempt off.
The Russians didn't even need a big game from Andrei Kirilenko, who came in second in the tournament with 23.3 points per game but had just eight on 2-of-8 shooting Saturday.
Marc Gasol and Rudy Fernandez each had 10 for the Spaniards in the first meeting since Russia stunned Spain, then the reigning world champions, 60-59 in the 2007 European championship game.
The Spanish, who barely beat Britain on Thursday, came to play with first place at stake, even using star guard Juan Carlos Navarro for just the second time in the Olympics as he recovers from injuries.
Pau Gasol opened the scoring with a three-point play and Marc converted one that made it 10-0 not even two minutes into the game. A jumper by Ponkrashov got Russia on the board, but Spain came back with 10 straight points, opening a 20-2 lead on a jumper by Fernandez with 4:42 remaining in the first quarter.
Spain led 28-11 after one before Russia finally got going in the second. Kirilenko finally scored with a pair of free throws with 5:48 remaining, kicking off a 12-2 run. Fridzon, who hit the winning 3-pointer with 4 seconds left in a victory over Brazil on Thursday, made four straight baskets to pull the Russians within 38-32 with 2:28 to go, and they were down eight at halftime.
Russia finally surged into the lead with a 9-0 run, Fridzon making consecutive jumpers at the end of it to make it 51-47. The Russians were ahead 56-53 headed to the fourth, but Spain seemed back in control when Marc Gasol's jumper made it 69-60 with 4:40 to play.
Russia didn't even qualify for the Olympics until a last-chance qualifying tournament in July, closes pool play Monday against Australia.
Spain will play Brazil, and assuming the teams enter tied, the loser would actually be in better position. The second-place finisher in Group B would have to face the Americans in the semis, while the third-place team would be on the other side of the bracket.