Kagiso Rabada took three wickets and Temba Bavuma produced a stunning piece of fielding as South Africa closed in on a first test victory by reducing Australia to 169 for 4, still 369 runs behind, at the end of the fourth day in Perth.
The hosts had started their pursuit of their unlikely victory target soon after lunch when South Africa skipper Faf du Plessis declared at 540-8, a lead of 538, having all but batted Australia out of the contest.
Bavuma's brilliant run out ended David Warner's bright start before 21-year-old Rabada removed Shaun Marsh, Steve Smith and Adam Voges to finish the day with figures of 3-49 off 16 overs.
Usman Khawaja survived an early scare when a DRS review saved him from a duck and will resume unbeaten on 58 with all-rounder Mitchell Marsh, who was 15 not out, as the Australians look to bat out the final day at the WACA.
Warner appeared ready to chase down the full 539 target himself when he opened the innings at a fair lick with 35 runs from 33 balls.
South Africa's pace attack, reduced to Vernon Philander and Rabada after the loss for the series of an injured Dale Steyn, were struggling for the breakthrough until the intervention of Bavuma.
Having just hit his sixth four, Warner was cantering down the wicket for a single when the diminutive Bavuma acrobatically swept up the ball and, while still airborne, flicked it at the base of the middle stump.
Marsh departed four balls later for 15, catching an edge to a Rabada delivery, but after Khawaja's reprieve off the first ball of the next over, Australia made it to tea without any further damage.
Smith looked set on 34 until Rabada finally got his length right and found a bit of outswing in a beautiful delivery that caught a fine edge off the bat and carried to Quinton de Kock behind the stumps.
Another superb Rabada delivery in his next over had Voges flummoxed and he departed for one run in similar fashion.
Australia captain Smith had earlier bowled Philander for 73 to bring an end to three hours of frustration for the hosts as South Africa added another 150 runs to their overnight tally of 390-6.
De Kock made 64 before he was caught at short leg but Philander and debutant spinner Keshav Maharaj (41 not out) continued to plunder runs off the exhausted Australian bowlers.
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 therefore be confident of taking a 1-0 lead in the three-match series, which continues in Hobart before concluding with a day-night test in Adelaide.