Trailing by a point at three-quarter time, it was a back-and-forth affair down the stretch with both sides trading baskets.
Patty Mills (30 points, three steals) put the Aussies ahead by a point with 1:42 remaining before Sergio Rodriguez answered with a jumper of his own 13 seconds later.
Inside the final minute, coach Andrej Lemanis drew up the perfect out of bounds play but Mills was unable to hit the shot. David Andersen followed the miss with a huge offensive rebound though and was sent to the free-throw line where he hit both shots.
Pau Gasol had the answer to once again put Spain ahead but inside the final ten seconds, Aron Baynes (six points, four rebounds) got his hook shot to fall and give Australia an 88-87 advantage.
Needing a stop to secure the win, Mills was then called for a questionable foul as he was falling backwards with an out of control Rodriguez running into him.
Regardless, the Spanish guard was cool from the free-throw line to give Spain the 89-88 lead and on their final offensive possession, Australia fumbled the ball and were not able to get off a legitimate attempt.
"It's pretty tough," said Andrew Bogut post-game. "This wasn't a goal, just to make the four, but that's sport."
“This is a very proud bunch of blokes," added Mills. "They fight hard for their country. So close but this is just more fuel for the fire for next time."
Fouls had been a concern for the Aussies all night as Bogut (two points, five rebounds) and Matthew Dellavedova (six points, eight assists) both subbed out early in the first period with two quick ones each.
However, it did not take the team out of their rhythm with Andersen (15 points, five boards) slotting in perfectly to keep the scoreboard ticking over.
Gasol (31 points) and Nikola Mirotic (14 points) proved a handful defensively though, hitting a number of jump shots while Gasol connected on alley-oop plays to take full advantage of Bogut's absence.
The Spaniards took a six-point lead into the first break and they began to heat up from distance in the second period through Mirotic and Victor Claver who combined for 5-6 long range shooting.
However, Andersen was able to answer, reaching double-figures alongside Mills who hit a couple of timely three-pointers himself.
Andersen was aggressive in his shot-taking and was fouled beyond the arc by Gasol just prior to half-time, cutting the margin to two points on a 10-0 run.
Coming back on to court out of the main break, Dellavedova handed Australia their first lead of the game with his trademark floater but a spanner was thrown in the works when Bogut fouled out, picking up another two fouls in succession.
This time, it was Brock Motum (12 points, six rebounds) and Ryan Broekhoff (13 points) who stepped up off the bench while Mills continued to utilise his speed to get to the rim, scoring 13 points in the third period while running rings around Ricky Rubio and Rodriguez.
Motum then brought the crowd out of their seats with a thunderous dunk over Gasol early in the fourth period, sparking a back-and-forth affair which would play out for the rest of the contest.
The full box score can be found here.
Speaking after the culmination of his fourth Olympics, Andersen said, "There's a great spirit [in this team] and hopefully the young fellas will carry the torch for the next [Olympics]."
That next Olympic campaign is Tokyo in 2020 and while the heartache from this game may take a little while to subside, this team has shown where Australian basketball is headed. That elusive medal is not far away.