Springboks captain Jean de Villiers pleaded with Irish referee George Clancy not to penalise his teammate, but Beale came on soon after to exploit the numerical advantage and earn a penalty. He then combined with the Waratahs-laden backline to put Horne over in the 78th minute.
Foley, who had a mixed night in his first international outing with halves partner Nick Phipps in wet and windy conditions, then kicked the conversion from 10 metres in from the sideline.
The Wallabies got off to a strong start after a leaping Israel Folau regained the kickoff, then ran on to a low pass from Matt Toomua to cross for a try after just 90 seconds.
Much of the visitors' early territorial dominance was due to a strong tail wind, and they made the most of it by plugging the corners and pinning the Wallabies in their own territory.
The tactics worked, and the Springboks negated the early Australia try through a penalty goal by Morne Steyn, then took the lead through a well-constructed try by winger Cornal Hendricks. The sides then traded two penalty goals for South Africa to lead 14-11 at halftime.
Springboks coach Heyneke Meyer was coy when asked about Habana's yellow card.
"I think you know the answer and I know the answer, so I'm not going to answer. The ref is always right," Meyer said. "I'd love to answer that question. But I'm not going into it. We don't want to use it as an excuse."
De Villiers was also diplomatic, saying he wanted consistency - especially considering Horne's high shot on himself minutes earlier in a similar position on the field.
"To sit here and complain about the referee's decision isn't our way. We'll just take this one on the chin," he said.
However, de Villiers did say it was a poor way for Habana to mark his 100th test.
"I do feel for him. Getting sin-binned on your 100th isn't the way he ever envisaged," he said.
Australia captain Michael Hooper praised Foley for his late goal-kicking.
"It's really comforting as a captain to know you've got a guy who can hit the pressure goals," Hooper said. "That was a tough kick."
Australia coach Ewen McKenzie celebrated his first win over a team ranked ahead of the Wallabies since taking over as coach.
"It was always going to be a game of character, and we came through," said McKenzie.
He also defended his decision to wait until late in the game to put Beale on at inside center.
"Everyone's an expert on who to pick, but I think we got a good outcome. Kurtley gave us a good second wave of attack in the last 10 minutes," he said.
"I always think of the bench as finishing the game and that's what they did."
Australia hosts Argentina next Saturday on the Gold Coast in the next round of the Championship, while South Africa plays New Zealand in Wellington.
Australia 24 (Israel Folau, Rob Horne tries; Bernard Foley conversion, 4 penalties); South Africa 23 (Cornal Hendricks try; Morne Steyn 6 penalties). HT: 11-14.
- AAP