Spain held off Australia in a controversial finale to claim a 89-88 victory in the bronze medal match at Rio 2016.
A thrilling encounter at the Carioca Arena saw 14 lead changes in the last five minutes but it was three-time silver medallists Spain that came out on top, but in highly dramatic circumstances.
Australia appeared set for triumph when Aron Baynes put them 88-87 ahead with a turnaround hook shot with 9.7 seconds remaining.
However, a controversial foul call against Australia's Patty Mills sent Sergio Rodriguez to the line for two free throws with five seconds remaining.
Rodriguez made no mistake in converting both and Australia were unable to get a shot off on their final possession.
The medal is Spain's third in as many Olympics following silvers in Beijing and London.
Pau Gasol led the way for Spain, as the San Antonio Spurs big man put up 31 points and 11 rebounds. His cause was aided when Australia's Andrew Bogut fouled out with just under eight minutes remaining in the third quarter.
Mills led Australia with 30 points on 11 of 23 shooting from the field.