A surprise recall in Dave Rennie's side, Cooper split the middle of the posts from 40 metres out on an angle after scrumhalf Nic White swooped with a turnover after the ball squirted out of the Springboks' scrum in a frenetic finish.
Cooper racked up 23 points in a flawless night off the tee, slotting seven penalties and a conversion, with Andrew Kellaway scoring the Wallabies' lone try in the 17th minute as they shelved their running game to upset the world champions.
True to form, the Springboks scored their three tries from line-out drives, with Malcolm Marx's second five-pointer putting the visitors in front with eight minutes left.
After referee Luke Pearce granted the Wallabies a last shot on goal, it was a toss-up between Cooper and team mate Reece Hodge, who has the longer boot of the two.
Cooper took the shot after Hodge told him to go for it.
"The first thing was, I looked up and I had a kick from a similar spot just before that and I only just had the legs to get it over," Cooper said.
"I had a little chat to myself and said: 'Is this your ego that wants you to take it?
"Your peers are backing you, you've got to back yourself as well."
The Wallabies claimed their first win of the tournament in front of 15,000 fans after back-to-back defeats by New Zealand at Eden Park and Perth.
"We were smart, we kicked appropriately, we played a fair bit of territory and got rewarded," Rennie told reporters.
"It's another learning curve."
After two weeks in COVID-19 quarantine, South Africa fell to their first loss after winning their opening two matches at home against Argentina.
Springboks coach Jacques Nienaber lamented his team's indiscipline in a match blighted by two yellow cards for each side.
"Australia played well, they deserved to win," he said.
"I don't think we were great today.
"I just thought we were a little bit off our game, especially from a discipline point of view."
South Africa will have another chance to end an eight-year losing streak in Australia when the teams meet in Brisbane on Saturday.
Despite the nerve-jangling finish, it was a largely dour contest marred by officious refereeing as the Wallabies emulated the Springboks' territorial game.
South Africa skipper Siya Kolisi was yellow carded for a lifting tackle on Tom Banks in the 16th minute.
That opened the door for Kellaway's try, with second-five Samu Kerevi stretching the Boks' defence with a linebreak before floating a long pass wide to the winger who cut in from the right flank to touch down.
South Africa hit back through forward muscle and Hooker Bongi Mbonambi fell over the line after Wallabies lock Matt Philip was yellow-carded for illegal maul defence.
Cooper's boot ensured Australia carried a 19-11 lead into a messy second half in which Springboks' fullback Willie le Roux drew yellow for a deliberate knock-on and Australia hooker Folau Fainga'a was also sent off for a no-arms tackle.
South Africa's beefy forwards soon came to the fore, putting Marx over near the hour-mark and again in the 72nd minute.
However, first-five Handre Pollard failed to convert Marx's second try, leaving the door open for Cooper's last-gasp heroics.