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.
The thrilling semi-final was 71-71 at the end of regulation time and the two sides could not be separated at the end of the first overtime.
Finally, the 2006 world champions Spain jubilantly emerged after the Boomers appeared to run out of juice.
Gasol, the 34-year-old Toronto Raptors centre, finished with 33 points after stepping up late in the breathtaking game when his country needed him most.
Red-hot Patty Mills was unfortunate to be on the losing side, leading Australia with 34 points.
The Australians, who had never gone beyond the quarter-finals in 11 previous attempts, had the whiff of revenge in their nostrils.
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.
This semi-final was billed as the Australian offence against the defence of Spain.
San Antonio Spurs livewire Mills has been one of the players of the World Cup in China 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 but missed the other and the match was level 71-71 at the end of regulation time.
The veteran Australian centre Andrew Bogut was again loudly booed and jeered by locals in the arena aggrieved at a tweet he sent in July about Chinese champion swimmer Sun Yang.
Australians in the crowd, many of them dressed in the national colours, chanted his name in support.