Pat Cummins turned it around for Australia in a day-changing eight-over spell in the final session, taking four wickets as South Africa crashed from 220-2 to 266-8 in the third test on Thursday.
Cummins removed AB de Villiers for 64 to end his 128-run stand with Dean Elgar and start South Africa's sudden slide at the end of the first day at Newlands.
Cummins added the wickets of South Africa captain Faf du Plessis (5), Temba Bavuma (1) and Quinton de Kock (3) as Australia took six wickets for 46 runs after tea.
Cummins claimed 4-12 in those eight overs in his devastating spell and Mitchell Marsh and Mitchell Starc pitched in to remove Vernon Philander and Keshav Maharaj.
Cummins said it was "up there" with his best spells in test cricket.
"It was one of those spells where the ball was going exactly where you want it," he said. "I thought the innings was slipping away from us.A brilliant final session."
Opener Dean Elgar was 121 not out — having been dropped on 53 and 87 — but South Africa's momentum had been completely removed by Cummins after the home team made a strong start to the crucial third test.
Australia was on top after struggling through the first two sessions. South Africa was 75-1 at lunch, added 110 runs for one wicket in the second session to be 185-2 at tea, then lost 6-81 in the last session.
"The way it was going at tea, I though we should push past 380, 400 (runs) here," Elgar said. "You just can't afford to play loose cricket."
The four-match series is level at 1-1, and South Africa initially had a significant advantage after winning the toss and opting to bat on a good pitch in Cape Town.
Despite the early loss of Aiden Markram for a duck, Hashim Amla (33) and Elgar put on 86 and Elgar and de Villiers then constructed their big century partnership that threatened to take the game away from Australia.
Cummins didn't let that happen with his brilliant burst.
Elgar battled gamely, hitting 17 fours and a six and batting all day for his 11th test hundred and first of 2018. He was the top run-scorer in test cricket in 2017.
But he watched on from the other end as de Villiers scooped a catch straight to David Warner at mid-off to start the collapse. Du Plessis, Bavuma, and de Kock all followed quickly, trapped on their crease by Cummins and edging behind to the slips or wicketkeeper Tim Paine.
"We spoke the whole day if we got one ... we'd be able to get two or three pretty quickly," Cummins said.
Cummins also laughed at suggestions he intentionally trod on the ball earlier in the day in an effort to unfairly rough it up to aid reverse swing, an incident the South African television broadcaster replayed on slow-motion a couple of times.
"What do you want me to say? It was just a mistake, yeah," Cummins said.
There was nothing in the Cummins incident, but this series has been full of contentious moments, starting with the off-field confrontation between Warner and de Kock in the first test in Durban, and continuing with South Africa fast bowler Kagiso Rabada's ban, and subsequent vindication, for bumping into Australia captain Steve Smith after getting him out in the second test.
As expected, South Africa selected Rabada after he had his two-match ban overturned on appeal this week, clearing him to play at Newlands. He was 6 not out alongside Elgar at stumps.
Australia won the opening test convincingly in Durban and South Africa replied with victory in Port Elizabeth.
While Rabada's successful appeal against an International Cricket Council ruling meant he was retained in the team, South Africa made two other changes. Batsman Bavuma was recalled after recovering from injury and fast bowler Morne Morkel was picked.
Australia, which hasn't lost a test series in South Africa since the end of apartheid, kept the same team that played the first two tests.