Following back-to-back defeats to New Zealand to start the competition, veteran fly-half Cooper was named in the starting line-up for the visit of the world champion – his first international appearance since June 2017.
The 33-year-old's kicking was exemplary, slotting through a seventh penalty and eighth successful kick of the game from 40 metres with the clock in the red to snatch the win at the death.
Handre Pollard and Cooper scored two penalties apiece before Siya Kolisi's yellow card for a dangerous tackle on Tom Banks was pounced upon by Australia.
Samu Kerevi's excellent pass released Andrew Kellaway, who cut in off the right wing and dived in behind the posts.
The Springboks responded well and Bongi Mbonambi powered over from the back of a driving maul after Matt Philip was sent to the sin bin for repeated ruck infringements, but the Wallabies still took an eight-point lead into the break.
Willie Le Roux was shown a yellow card for a deliberate knock-on in the 52nd minute and he was joined in the bin by Folau Fainga'a before replacement hooker Malcolm Marx touched down in the middle of another driving maul.
Marx did likewise in the 72nd minute for his second try to put the Springboks in front, but Damian Willemse made a costly miss when attempting to convert from the tee.
And after South Africa conceded a penalty at the death for not releasing on the ground, Cooper made them pay with a winning kick.