South Africa made steady progress in their attempts to pull off an impressive victory over Australia in the first Test and will start day five just six wickets from winning.
Batting throughout day three had put the Proteas in control at the WACA and they pressed home their advantage on Sunday as Quinton de Kock (64) and Vernon Philander (73) took South Africa to a mammoth 540-8 declared, setting Australia 539 to win.
After Temba Bavuma struck first blood with a wondrous run-out of David Warner (35), Kagiso Rabada (3-49) then took over with two exceptional spells of fast bowling, shouldering the responsibility of leading the attack admirably in the absence of the injured Dale Steyn.
Shaun Marsh (15) and Adam Voges (1) had no answer to the prodigal quick and he also accounted for Steve Smith (34) as the Australia captain had looked set to build a useful union with Usman Khawaja, who ended day four unbeaten on 58 with Australia still 369 runs in arrears on 169-4.
The powerful left-hander has a stunning record in home conditions, where he has scored three of his four Test hundreds, and will be key for the home side as they attempt a gritty defensive effort on Monday.
Australia's task was always going to be a stiff one, but De Kock and Philander made it nigh-on impossible from the start of the day, swiftly taking the hosts' prospective target into world-record territory and then to another realm entirely.
De Kock's innings was especially full of highlights, launching two huge sixes down the ground as well as surviving being given out twice thanks to DRS.
Australia looked bereft of ideas and their woes were summed up as Josh Hazlewood dropped Philander over the rope for six off the bowling of a seething Mitchell Starc.
De Kock eventually perished when a Mitchell Marsh delivery sprung from a crack and popped up for Voges at cover, while Smith bowling Philander prompted the Proteas' declaration.
Warner and Khawaja had started positively, despite a number of deliveries either staying low or taking off thanks to the WACA's infamous cracks.
However, Bavuma astonishingly set South Africa on their way, racing onto a dab down from Warner in front of point before diving, twisting and throwing down the stumps from a horizontal, mid-air position.
Shaun Marsh followed four balls later, edging Rabada to slip, as Australia's players seemed as stunned as their fans.
Khawaja survived a verdict of out the very next ball - given caught behind though the ball clipped pad, not bat - and the left-hander survived another life when Hashim Amla grounded a sharp chance low to his right as Rabada again excelled.
South Africa captain Faf du Plessis burned a review trying to oust his counterpart Smith, but the home skipper's 91-ball effort was ended by a marvellous piece of Rabada bowling as late, late outswing took the edge through to De Kock.
Reverse swing was now in full effect and, an over after Khawaja reached 50, Voges was given a spectacular six-ball grilling from Rabada, from which the batsman had no answer before another feather edge ended his torment.
Mitchell Marsh (15 not out) safely negotiated the end of day's play alongside Khawaja. The pair will need to produce something heroic on the final day to deny the Proteas.