Rob Horne scored a brilliant converted try two minutes from time to give Australia a 24-23 victory over South Africa in the Rugby Championship at a rain-soaked Subiaco Oval on Saturday.
Fullback Israel Folau crossed for his 15th test try after two minutes but for much of the rest of the evening Australia were chasing the game and it was only when winger Horne went over in their best move of the match that victory looked likely.
South Africa had a try from winger Cornal Hendricks and six penalties from six attempts from Morne Steyn but will rue the harsh 65th minute yellow card shown to winger Bryan Habana, who was playing his 100th test.
Flyhalf Bernard Foley, who also kicked four penalties, stepped up to nervelessly convert Horne's try and give coach Ewen McKenzie his first win over one of the southern hemisphere superpowers since he took over last year.
"So proud of the guys to get through tonight," said Australia captain Michael Hooper.
"We thought it was all in our control (but) too many soft, easy penalties. They were punishing us because Morne can kick it from anywhere, so we have got to get better at the start of the game.
"But can't be any happier with a winger scoring in the corner to win the game. Lovely."
Australia got off to the best possible start when sustained early pressure allowed Folau to score the game's opening try after two minutes, the fullback picking up Matt Toomua's pass at knee level and sliding over the try line.
Steyn cut the early deficit with his first penalty and after 12 minutes the Springboks were ahead through a well-worked score from Hendricks.
Coming off an attacking lineout, the South Africans moved the Australian defence over to one side of the pitch then swept back to the other corner where the winger cut inside Nick Phipps to score.
Foley levelled the scores up after 17 minutes but two Steyn efforts from the tee punished Australian indiscipline and the Springboks were soon 14-8 ahead.
The scores were all square again soon after halftime after two more penalties from Foley but more problems with the Australian scrum, taken apart by the All Blacks two weeks ago, allowed Steyn to quickly put the visitors 20-14 in front.
Habana, seeking his 10th try against Australia, nearly put South Africa in for spectacular try with a trademark burst down the left wing but scrumhalf Ruan Pienaar spilled the ball.
Australia were now making basic mistakes - twice fluffing restarts - and always looked like coming off second best when they took to the skies to engage in kicking duels.
Steyn edged the Springboks further ahead just after the hour mark when James Horwill was penalised at the tackle soon after coming on as a replacement at lock.
Habana was sin-binned for a high tackle on Adam Ashley-Cooper after 65 minutes but Australia were initially unable to capitalise to any telling effect.
Prop Pek Cowan crashed over the line almost immediately only for referee George Clancy to penalise Rob Simmons for taking out his fellow lock Eben Etzebeth.
Foley cut the deficit to six points with his fourth penalty after 68 minutes but the Springboks defence held strong with the Wallabies hammering at the door until Habana returned.
Just when they thought they had got away with it and with victory in sight, however, the Wallabies backline, enlivened by the injection of replacement Kurtley Beale, got ball through hands at pace to set Horne free down the left wing.
"I thought we played pretty well in stages," said South Africa captain Jean de Villiers.
"Credit to Australia, they played really well and fought right to the end and scored a really great try in the end so well done to them.
"It was a bit tough to defend with 14 at the end there and we had a couple of mistakes that cost us. We need to work hard to come back next week."
Australia host Argentina on the Gold Coast next week, while the South Africans move on to Wellington to play the world champion All Blacks.