Canada eliminated champions Spain 88-85 in a thriller in Jakarta on Sunday to book their place in the FIBA Basketball World Cup quarter-finals in Jakarta, while the United States were beaten by Lithuania in their final preliminary game.

The final day of preliminary games in Japan, Indonesia and the Philippines offered surprising results as the quarter-final line-up was completed.

Lithuania, ranked eighth in the world, will face Serbia while the U.S. will play Italy in the last eight.

Germany will meet Latvia and Canada will lock horns with Slovenia.

Canada’s Shai Gilgeous-Alexander, an NBA All-Star with the Oklahoma City Thunder, scored a game-high 30 points, the most for a Canadian player since 1994.

“We’re willing to do whatever it took and we ended up getting it done,” said Gilgeous-Alexander, who scored Canada’s last eight points including six clutch free throws to complete a comeback win.

Canada beat Spain for just the second time in the tournament’s history, snapping a 49-year winless streak against the top-ranked European powerhouse.

Spain’s Alex Abrines missed a potential game-tying three-pointer at the buzzer. Spain, missing 2019 World Cup’s most valuable player Ricky Rubio who stepped away from the sport to focus on his mental health, suffered their first back-to-back tournament defeats since 1990.

Canada also qualified for the 2024 Paris Olympics, their first since 2000.

In Manila, Team USA lost to Lithuania 110-104 in a quarter-final seeding game.

Lithuania led throughout, building a 54-37 advantage by halftime through three-pointers, second-chance points, and buckets from Team USA turnovers.

“They tried to be aggressive against us but we stayed calm and we take the win,” Lithuania’s Donatas Motiejunas, who scored nine points, told reporters.

Seven Lithuanians scored in double-digits, led by Vaidas Kariniauskas’ 15 points. Anthony Edwards of the NBA’s Minnesota Timberwolves led the scoring for the U.S. with 35 points.

Team USA narrowed the gap to four points with 30 seconds to go in the third quarter, and Edwards tried to lead a comeback in the final frame.

“Lithuania obviously just came out of the gates on fire,” Team USA head coach Steve Kerr said. “We are fortunate that the loss doesn’t hurt us in terms of our goal which is to win the gold medal.”

In other games with quarter-finals implications, Serbia routed the Dominican Republic 112-79 in Manila, and Italy defeated Puerto Rico 73-57 for a return to the quarter-finals after 25 years. Germany outlasted Slovenia 100-71 in Okinawa while Latvia won against Brazil 104-84.

FIBA’s flagship event, co-hosted by the Philippines, Japan, and Indonesia, will run until Sept. 10.