Australia held on with 11 men in a dramatic finish to beat a second-string South Africa outfit 42-38 at Perth Stadium on Sunday and extend their unbeaten run to five games since new coach Les Kiss took over in late July.
Skipper Harry Wilson, Ryan Lonergan, Joseph Suaalii and Hunter Paisami were all shown yellow cards in the last 10 minutes as the world champions cut a 25-point deficit down to four at the final whistle.
Australia had looked to be cruising after centre Len Ikitau's double and tries from flyhalf Ben Donaldson, number eight Wilson and winger Max Jorgensen combined with 17 points from the boot of scrumhalf Ryan Lonergan gave them a 42-17 lead after 65 minutes.
The last 10 minutes threatened to undo all their earlier good work but the Wallabies will move on to back-to-back tests against the All Blacks in October without a loss in six games, their best unbeaten run since 2017.
"I'm so proud of the group," said Wilson. "We versed the world champions in our own backyard here. Jeez, that was a crazy last 10 minutes, but that first 70 minutes, the way we played, we implemented our game plan in exactly the way we wanted."
South Africa coach Rassie Erasmus had made 13 changes to his lineup from the team which completed the gruelling 3-1 series victory over New Zealand earlier this month but stacked his bench with first-choice players as an insurance policy.
It almost paid off in the frantic last 10 minutes, but scores from hooker Johan Grobbelaar, winger Edwill van der Merwe, scrumhalf Morne van den Berg, prop Ox Nche as well as a penalty try were not quite enough.
"Australia is always a hard team to beat, and such a good game to play," said Springboks captain Andre Esterhuizen.
"It was a pretty intense game and quite quick for a test match, but they capitalised on all our errors, and I think discipline let us down, especially in that first half."
The visitors scored the first try after Handre Pollard and Lonergan had exchanged early penalties with Grobbelaar rolling over the line on the back of a rolling maul.
Australia responded with two tries from Ikitau in three minutes, the first from close range and the second after winger Suaalii had disrupted the restart and the ball bounced back to the lurking centre.
The Springboks responded almost immediately to lock up the scores again at 17-17, flyhalf Pollard's long pass exposing a hole in the Australian backline defence and Van der Merwe showing his pace to finish the move.
A slanted crosskick from Wallabies fullback Tom Wright gave Jorgensen some space to run shortly before halftime, however, and Australia recycled patiently when the winger was held up shy of the line with Donaldson going over unopposed in the corner after 14 phases.
Lonergan extended Australia's lead with his second penalty eight minutes into the second half, prompting Erasmus to bring on all eight of his replacements, and added a third three-pointer after 54 minutes to make it 30-17.
The Wallabies were now taking the Springboks on up front and tapped a penalty close to the line just before the hour mark with Wilson forcing his way over and slapping the ball down for a try.
The Springboks stormed back to try and cut the 20-point deficit but when Canan Moodie spilled the ball, Jorgensen was on hand to scoop it up and sprint 60 metres for Australia's fifth try.

Czechs down Ukraine to claim 12th Billie Jean King Cup crown
Fernandez beats Gibson to win Singapore Open title
World champions Spain defeat England at Nations League thriller
Saudi Arabia reach Gulf Cup semis as Iraq win thriller
