Man of the match James Hook put Wales ahead with a calmly taken drop-goal with eight minutes left but the Wallabies launched one last desperate attack and made it count.
Wales led 17-0 after a bizarre opening 21 minutes in which the hosts made all the running and the visitors scored all the points.
As the Wallabies launched their first attack, captain Stirling Mortlock fumbled a pass and it fell kindly for Chris Czekaj. The Cardiff Blues raced away and hacked ahead.
Matt Giteau seemed to have the threat covered, but he failed to control the ball and James Hook seized the opportunity to send Wales' new record cap-holder, captain Gareth Thomas, crashing over after just 75 seconds.
Hook converted and then watched as Mortlock hit an upright as the Wallabies continued their ferocious early assault.
Things went from bad to worse for the hosts after 16 minutes when Jamie Robinson intercepted full-back debutant Julian Huxley's pass to race clear from 70 metres.
Hook again converted and added a penalty five minutes later after Jonathan Thomas sent Lee Byrne on another Welsh break-out.
Then the home fightback began, number eight Wycliff Palu crossing at the corner as another series of sweeping Wallaby attacks paid dividends.
That 24th-minute try was followed 10 minutes later by second-row Nathan Sharpe barging past Robert Sidoli on his way to the line and Mortlock kicking his first shot from three attempts to put his side within five points of the tourists.
Wales suffered a further blow when Australian-born Brent Cockbain left the fray after 35 minutes, replaced by Michael Owen, a specialist number eight, while Gavin Henson also returned to action as a blood-bin replacement for skipper Thomas.
Hook extended Wales' lead 11 minutes after the break with a penalty before Matt Giteau took full advantage of a defence in disarray to skip around the blindside from close-range and Mortlock again converted to put his side within a point at 19-20 behind with 25 minutes to go.
Mortlock then stepped up to do the captain's job by kicking a 63rd minute-penalty before a Hook penalty struck an upright two minutes later.
Hook made amends with the drop-goal that put Wales back into the lead after 72 minutes only for the number eight replacement to cross at the death for the killer blow.