South Africa set Australia an imposing target of 539 runs to win the first test after declaring on 540 for eight in the fourth over after lunch on the fourth day at the WACA on Sunday.
Faf du Plessis brought South Africa’s second innings to a close after Vernon Philander had been bowled for 73 by Australia captain Steve Smith. Debutant spinner Keshav Maharaj finished 41 not out.
The highest successful fourth-innings run chase in test cricket was the 418-7 West Indies scored to beat Australia at Antigua in May 2003, while South Africa scored 414-4 to beat their hosts at the WACA in 2008.
The Proteas will be confident of taking a 1-0 lead in the three-match series with nearly five sessions remaining over the last two days of the test.
They will have to take 10 Australian wickets without Dale Steyn, however, after their pace spearhead was ruled out of the series by a shoulder injury on Friday.
After two days of dominance from South Africa, the hosts would have arrived at the ground aiming to remove the last few batsman as quickly as possible and get on with the run chase.
The tourists resumed on 390-6 on another hot morning in Perth and reached lunch at 508 for seven with Quinton de Kock (64) the only batsman to fall in the first session.
De Kock was given out twice before his dismissal, once off quick Josh Hazlewood and once off spinner Nathan Lyon, but he reviewed both immediately and was vindicated by the DRS technology.
Philander survived a scare when it looked like he had holed out to fine leg off Mitchell Starc but Hazlewood spilled the ball onto the boundary rope to give up a six.
Mitchell Marsh finally made the breakthrough half an hour before the break when he got a little bit of bounce off the wicket and de Kock popped the ball up invitingly to Adam Voges at short leg.