Serbia had the best offense of the tournament heading into Sunday's encounter, but Spain held firm in Wuhan to secure an 81-69 victory and top spot in Group J.
Meanwhile, Italy ended their campaign with an impressive comeback against Puerto Rico, Tunisia came out on top by just two points against Angola and South Korea got the better of Ivory Coast.
RUBIO RUNS THE SHOW AS SPAIN STALL SERBIA
Ricky Rubio was in scintillating form as he scored 19 points and added four assists to lead Spain to victory over Serbia, who suffered their first defeat since February.
Rubio was backed up admirably by Marc Gasol and Victor Claver, as Spain earned a fifth successive win.
It was the first time Serbia failed to score 70 points or more in a World Cup match, even though Bogdan Bogdanovic grabbed 26 points in a supreme individual display.
While Spain will face Poland in the last eight, Serbia must rally for a tough test against Argentina.
NIGERIA BOOK OLYMPIC SPOT
Josh Okogie helped himself to 19 points for Nigeria, with 11 coming in the final quarter. Jianlian Yi was the start of the show with 27 points, but his performance was not enough to secure a Chinese victory.
Nigeria's NBA forward Al-Farouq Aminu said on the FIBA website: "I remember when I joined the team in 2012 we said we did not want to miss an Olympics. It's a beautiful feeling. It's amazing."
China are in danger of missing out on direct qualification for the Olympics, with Iran going above them in the race for Tokyo thanks to their 95-75 win over Philippines.
AZZURRI FIGHT BACK TO OVERCOME PUERTO RICO
Marco Belinelli and Danilo Gallinari inspired Italy to overcome a 26-point deficit as the Azzurri triumphed 94-89 in overtime against Puerto Rico to end a frustrating campaign on a positive note.
Italy had never previously won a World Cup match in which they trailed by 15 points or more at half-time, but Belinelli and Gallinari rallied their team-mates after a timeout taken when 59-33 behind midway through the third quarter.
Belinelli converted a game-high 27 points, while Gallinari became the first Italy player to accumulate more than 20 points, five rebounds and five assists in a World Cup game since 1994.
"It was a very bad game for us in the beginning. We did not show up," Gallinari said. "We knew that we had to come out with a different attitude and different intensity in the second half and I think that we did a great job."