Ryan Rickelton and Wiaan Mulder were the catalysts for South Africa's fightback at Newlands, as the hosts recovered from a precarious position to set Australia 288 for victory in the third Test.
South Africa resumed on 140/4, holding a slender 40-run lead after Australia had made 429 in their first innings, with Matthew Breetzke and Rickelton having seen out the final stages of day three.
The pair continued to grind their way through the morning, adding 41 before Breetzke was dismissed for a determined 43 off 121 balls at 181/5.
That brought Mulder to the crease and began the partnership that would change the complexion of the innings.
Rickelton and Mulder initially focused on consolidation, absorbing Australia's pressure and steadily taking the sting out of the attack.
Working in tandem, Rickelton reached his 50 from 105 balls, while Mulder provided patient support at the other end.
Their partnership passed 50 from 88 balls and then 100 from 193, with the hosts gradually building a lead that began to look increasingly useful.
The pair did not simply shut up shop, though, gradually finding opportunities to increase the scoring rate as their confidence grew.
The home side reached the tea break on 294/5, with Rickelton on 83 and Mulder on 46.
The partnership eventually reached 150, with Mulder bringing up his half-century from 138 balls before Rickelton completed his century from 218 deliveries.
Rickelton's innings ended on 101, however, when he was run out at 335/6 after 219 balls, ending a sixth-wicket stand worth 154.
The dismissal sparked a brief collapse.
Marco Jansen fell for a duck eight balls later and Simon Harmer followed for one, leaving South Africa 344/8 and Australia suddenly sensing an opportunity to limit the target.
However, Mulder refused to let the innings unravel.
He reached his century from 204 balls and continued to shepherd the lower order, eventually making 115 from 221 deliveries before Pat Cummins had him caught by Mitchell Starc as the final wicket.
SA were bowled out for 387 in 134.4 overs, setting the tourists a target of 288 for victory.
The final few wickets were scrappy but still added to the value of Mulder's effort, with Gerald Coetzee and Kagiso Rabada helping South Africa move towards 350 before the innings finally closed.
Rabada was unbeaten on two when the innings ended.
The final total was built in stages: Breetzke's 43 helped South Africa survive the early part of the day, Rickelton and Mulder then combined for 154 to take the game away from Australia for a period, and Mulder's century ensured the hosts recovered after the late wobble.
Rickelton's 101 was built around patience and accumulation, while Mulder's 115 became the highest score of the innings and the decisive contribution in carrying South Africa through the final stages.
Australia's attack eventually regained control, with Mitchell Starc taking three wickets and Pat Cummins and Nathan Lyon two each.
But South Africa had done enough to give themselves a chance of victory, leaving Australia requiring 288 on the final day.