In a thrilling finish, Turkey defeated holders Spain 65-57 in the penultimate game in Group A.
Up 55-49 at the end of the third, Spain only managed a Felipe Reyes field-goal, as Turkey reeled off 16 unanswered points to snatch victory.
Emir Preldzic hit 18 points for the World Championship silver-medallists as Turkey join Spain and Lithuania in the next round.
Spain rested Pau Gasol as a precaution. His brother Marc led Spain with 12 points.
“Coach Scariolo did not want to risk Pau (Gasol) tonight. We are through so it’s about our key player safe and free from injury,” A Spanish official said.
It was a slow start but Marc’s turnaround jumper on the baseline gave Spain a 9-6 lead halfway through the first.
Despite Hedo Turkoglu’s best efforts, Spain had a comfortable nine point lead after one (19-10)
Preldzic trimmed the lead to start the second quarter. But Rudy Fernandez restored Spain’s cushion with a leaning triple to make it 29-23.
Omer Asik tied the game at 35 near the end of the half but Jose Calderon had other ideas by hitting from three-point land to give Spain a 38-35 half-time lead.
Serge Ibaka got the holders going in the third with back-to-back buckets to give Spain a six-point advantage.
Turkey tried staying in touch, but Spain seemed to be one-step ahead. Marc Gasol made it an eight-point lead (48-40)
Endar Arslan kept Turkey ticking towards the end, but Spain had a 55-49 lead heading in to their nightmare final period.
Turkey coach Orhun Ene afterwards paid tribute to Great Britain for assisting his side to Vilnius.
“We are here because of Great Britain,” Ene said.
“We hold Spain to just two points is great, our chemistry is good, and I feel good about Vilnius”.