Rhys Priestland's last-gasp penalty gave Wales a dramatic win over Australia's 14 men after a staggering end to an incident-packed encounter in Cardiff.
Andrew Kellaway gave the Wallabies an early lead but Rob Valetini's red card for a head-on-head tackle on Adam Beard turned the game for Wales, who forged ahead with a try from Ryan Elias while Kurtley Beale's sin-binning had temporarily reduced the visitors to 13.
Nick Tompkins' opportunistic score early in the second half gave Wales a little breathing space and a 23-13 lead, only for replacement Gareth Thomas' needless yellow card to wipe out the hosts' man advantage for a tense 10-minute spell.
During that period, Nic White finished a dazzling team move to bring Australia within three points of their anxious opponents and, after Dan Biggar's penalty nudged Wales further in front, Filipo Daugunu acrobatically touched down in the corner to cut the lead to just one point.
James O'Connor's touchline conversion hit the post but with a little over two minutes left, Beale - whose last-ditch try had snatched a dramatic win at the same venue in 2012 - looked to have hit the match-winning penalty.
Then to add to the remarkable late scenes, Wales forced their way back upfield and although their assault on the Australian tryline was repelled, replacement Priestland struck the winning points with the final kick of the game.
It was an utterly captivating conclusion to another gripping encounter between these familiar foes.
Victory gives Wales a third successive win over Australia, having lost 13 games in a row against the same team between 2008 and 2017, albeit with only two of those defeats coming by nine points or more.
The result also means Wales end their autumn campaign with two wins from four, while a third successive defeat completes a miserable tour for the Wallabies.
Depleted Wales capitalise on Australia's red mist
This has been a bruising autumn for Wales, whose long list of injured absentees for this game included British and Irish Lions Alun Wyn Jones, Ken Owens, Ross Moriarty, Taulupe Faletau, Justin Tipuric, Josh Navidi, Leigh Halfpenny and George North.
Any country would miss that volume and quality of talent, though few top-tier nations have as shallow a pool of players to choose from as Wales.
That is why head coach Wayne Pivac has been so determined to improve Wales' strength in depth and, in this series alone, he has used close to 40 different players.
Pivac was under pressure following defeats against New Zealand and South Africa and an unconvincing win over Fiji, and he will have feared a third loss from four when Australia made a flying start.
But as was the case against Fiji the previous weekend - and for the sixth time in 12 Tests this year - Wales were handed a major advantage in the form of an opposition red card.
There was no doubt about Valetini's dismissal. The Australia number eight charged into Beard, his head making contact with his opponent's face and forcing the Wales lock off injured.
Biggar's second penalty reduced Wales' deficit to 10-6 and, only seven minutes after Valetini's red, Beale was shown a yellow card for deliberately knocking on a pass from Tompkins.
The punishment got worse seconds later as hooker Elias combined with scrum-half Tomos Williams to score his third try in two appearances.
Wales were not so clinical from that point, struggling for fluency in attack against their dogged opponents and having to rely on Tompkins' fortuitous score to stretch their lead.
The centre looked to have knocked on as he intercepted a pass from Tom Wright but, after referee Mike Adamson checked with TMO Marius Jonker, the ball was deemed to have gone back and Tompkins' try stood.
Wales' losing run against Australia was characterised by agonising late scores and it looked like the Wallabies would come back to haunt them when White and Daugunu crossed, and particularly as their tormentor in chief Beale struck a 45-metre penalty.
But Wales were not to be denied in the same way this time. Roared on by a vociferous home crowd gripped by the late drama, they marched their way into the Australian 22 and Priestland delivered the decisive blow.
Teams
Wales: L Williams; Rees-Zammit, Tompkins, Halaholo, Adams; Biggar, T Williams; W Jones, Elias, Francis, Beard, S Davies, Jenkins (capt), Basham, Wainwright.
Replacements: Dee, G Thomas, Lewis, Carter, Tshiunza, G Davies, Priestland, McNicholl.
Australia: Beale; Kellaway, Ikitau, Paisami, Daugunu; O'Connor, White; Slipper (capt), Latu, Tupou, Arnold, Rodda, Leota, Samu, Valetini.
Replacements: Fainga'a, Bell, Alaalatoa, Skelton, Swinton, McDermott, Foketi, Wright.
Match officials
Referee: Mike Adamson (SRU)
Assistant referees: Mathieu Raynal (FFR), Nika Amashukeli (GRU)
TMO: Marius Jonker (SARU).