Dean Elgar and JP Duminy forged a magnificent third-wicket partnership and both struck centuries as South Africa took command of the first Test with Australia on day three at the WACA.
The tourists had closed day two on 104-2 - a lead of 102 - in their second innings following a first-innings collapse from Australia, with Elgar and Duminy both well set at the crease.
And the duo guided South Africa to a position of control by frustrating the Australia attack with a stand of 250.
Australia made late inroads to reduce the Proteas to 390-6, though the hosts now trail by 388 and face a daunting task over the final two days to avoid defeat.
Elgar and Duminy negotiated the opening session despite the ball providing plenty of swing for the Australia seamers.
South Africa reached 183-2 at lunch but Duminy hit five of his 20 fours inside three overs upon the resumption to signal his intent.
And the all-rounder promptly reached only his fifth Test century by hitting Mitchell Marsh (1-52) to cover for two.
The boundaries continued to flow and Elgar - having survived when Mitchell Starc was unable to claim a heave to mid-off - went to three figures for the fifth time in the eighth over with the new ball by smacking a four through the covers.
Duminy's excellent innings was ended on 141 as he was given out caught behind off Peter Siddle's (2-47) bowling nine runs short of his next milestone.
Elgar (127) eventually followed him back to the pavilion, paying the price for a poor shot by edging Jose Hazlewood (2-93) to Starc at gully.
Temba Bavuma (8) went cheaply as Australia began to enjoy more success, but Quinton de Kock (16 not out) and Vernon Philander (23no) shared seven boundaries to take South Africa's lead close to 400 and further tighten the Proteas' grip on a Test that once appeared to be getting away from them.