Australia faces the ignominy of losing the opening test of the summer for the first time in 28 years after South Africa set the hosts a record 539 runs to win at the WACA on Sunday.
Australia was 169-4 at stumps on day four with Usman Khawaja on 58 not out and Mitchell Marsh 15 not out.
The home side need a further 370 runs in a minimum of 90 overs on the last day for the highest successful run-chase in test history.
Fast bowler Kagiso Rabada made up for the loss of the injured spearhead Dale Steyn by claiming 3-49 including the prized wicket of skipper Steve Smith (34) that ended a threatening 92-run stand for the third wicket with Khawaja.
Australia stuttered to 52-2 before tea then counterattacked through Khawaja and Smith before Rabada struck.
Rabada took 2-0 in the space of nine balls in an outstanding nine-over spell of reverse swing bowling. He had Smith and Adam Voges (1) caught behind by wicketkeeper Quinton de Kock.
A defeat will be embarrassing for Smith’s team given that Australia hasn’t lost the first home test since losing to the West Indies at the Gabba in 1988.
South Africa declared on 540-8, leaving Australia at least 143 overs in four sessions to post the highest ever fourth-innings score to win and take a 1-0 lead in the three-match series.
The highest successful run-chase belongs to the West Indies when Brian Lara’s side chased 417 against Australia and won by three wickets in Antigua in May 2003.
Australia raced to 52-0 with David Warner kick starting the run-chase with 35 off 33 balls with six fours. But one ball after edging fast bowler Kagiso Rabada perilously over second slip, Warner was run out when an airborne Temba Bavuma scored a direct hit at the bowler’s end to catch the opener short of his crease.
Four balls later, opener Shaun Marsh (15) edged Rabada to second slip Faf du Plessis as Australia stuttered to 52-2.
Australia could have been in further trouble had Khawaja (0) not successfully challenged a caught behind verdict. Khawaja also got another reprieve on 41 when first slip Hashim Amla dropped a difficult edge off Rabada.
The tourists declared after lunch when Vernon Philander fell for 73, leaving debutant Keshav Maharaj unbeaten on 41 following a 72-run stand for the eighth wicket.
Overnight pair de Kock (64) and Philander batted untroubled in a 116-run seventh wicket stand as the game gradually drifted away from Australia.
With the wicket suiting batsmen despite widening cracks, South Africa ground out the Australian attack after starting the day on 390-6.
De Kock, who was the mainstay in South Africa’s first innings total of 242 with a brilliant 84, made a plucky 64 to again thwart Australia’s hopes of making early inroads in the tourists’ lower order.
Australia came close to dismissing him twice in the first hour when he was adjudged out by the onfield umpire. But the left-hander successfully challenged the caught behind and the lbw on 28 and 47, respectively, much to the dismay of the hosts.
De Kock finally drove uppishly and was well caught by Adam Voges at cover off Mitchell Marsh (2-77). He hit two sixes and five fours off 100 balls in 2 1/2 hours.
Philander batted for three hours and hit two sixes and 10 fours, while Maharaj’s 34-ball knock included three sixes and two fours.
This was after Dean Elgar (127) and Jean-Paul Duminy (141) on Saturday shared a 250-run third wicket stand to bat the Proteas to a match-controlling position.