NBA champion Marc Gasol saved Spain on Friday as they battled back to beat Australia 95-88 after a second overtime period and reach the Basketball World Cup final.
They will face either France -- quarter-final winners over reigning two-time champions the United States -- or Argentina in Sunday's decider in Beijing.
A thrilling semi-final was 71-71 at the end of regulation time and the two sides could not be separated at the end of a nervy first overtime.
Finally, the 2006 world champions Spain jubilantly emerged after the Boomers appeared to run out of juice.
Sergio Llull hit two three-pointers in the second overtime for Spain to cap their comeback.
Gasol, the Toronto Raptors centre, finished with 33 points, six rebounds and four assists after stepping up late in a breathtaking game when his country needed him most.
"We came back, we stuck together through tough times, that means a lot," said the 34-year-old, a three-time NBA All-Star.
The Spaniard played a key role in the Raptors' historic run to the NBA crown and knows that victory on Sunday will cap the perfect season.
"It's been great, I have been very fortunate," he said.
"I knew that it would not be easy physically (going from the NBA Finals to the World Cup) but it's definitely worth it.
"Not because of the final but passing along those values to the team. It's our turn to pass on the legacy to the next generation (of the Spain team)."
Ricky Rubio was also pivotal once more for Spain with 19 points, 12 assists, seven rebounds and four steals.
Red-hot Patty Mills was unfortunate to be on the losing side, leading Australia with 34 points.
- 'Hell of a game' -
The Australians, who had never gone beyond the quarter-finals in 11 previous World Cups, had the whiff of revenge in their nostrils -- and a first final.
Spain edged the Boomers 89-88 in the bronze-medal match at the Rio 2016 Olympics and the Australians had waited three long years to get their own back.
In San Antonio Spurs livewire Mills they had one of the players of the World Cup and his three-pointer midway through the second quarter put Australia 27-22 in front.
The in-form guard pulled off the same trick with 88 seconds left on the clock in the second quarter to give Australia a 37-32 advantage at the break.
But Spain slashed the lead to four points going into the fourth quarter and then just two points with 3:44 left.
Spain were just one point behind with 28 seconds to run and they had the momentum. Gasol, nerves of steel, nailed two free throws to put Spain up 71-70.
Mills then made one free throw with four seconds left but missed the other and the match was level at the end of regulation time.
Despite the crushing disappointment, Australia will need to raise themselves for Sunday's bronze-medal match and this is still their best World Cup performance.
Coach Andrej Lemanis called it "a hell of a game of basketball and fun to be involved with".
"Tough to lose, no doubt, it comes down to a couple of plays here and there," he said.
"At the end of the day, we had chances to win the game, we had every opportunity to win the game."