Rabada strikes late after De Villiers ton leaves Australia in trouble
Usman Khawaja made 75 but his dismissal just before the close has South Africa sensing victory at St George's Park.
Australia ended day three of the second Test on 180-5, a lead of 41, after an unbeaten hundred from AB de Villiers helped South Africa seize control in Port Elizabeth.
De Villiers posted his first three-figure score in the Test arena since January 2015, finishing up on 126 not out from 146 deliveries in the Proteas' first innings.
With help from Vernon Philander (36) and Keshav Maharaj (30), the right-hander steered the home side to 382 all out, giving them a commanding 139-run advantage.
Australia erased the deficit thanks mainly to Usman Khawaja's 75 but the left-hander fell just before stumps, trapped lbw by the impressive Kagiso Rabada (3 for 38).
Rabada had earlier dismissed David Warner (13) - although he risks further sanction after a send-off that saw him scream in the batsman's face - and Shaun Marsh (1), while fellow seamer Lungi Ngidi removed Cameron Bancroft, the opener bowled for 24 via an unfortunate deflection off his left boot.
Spinner Maharaj claimed the key scalp of Steve Smith, Australia's captain caught behind off an outside edge for 11 as his side slumped to 86-4.
Mitchell Marsh - who put on 87 for the fifth wicket with Khawaja - will resume on day four unbeaten on 39, yet Rabada's late strike leaves Australia facing an uphill battle to avoid a defeat that will level the four-match series.
De Villiers reached his 22nd Test ton prior to lunch, ending a barren run that stretched back to a knock of 148 against West Indies at Cape Town over three years ago.
Philander - who resumed unbeaten on 14 in the morning - stuck around for the first hour before fending a Pat Cummins short ball to Bancroft at short leg, ending an 84-run stand for the eighth wicket.
In contrast, Maharaj opted for an aggressive approach at the crease, smashing three fours and two sixes in a 24-ball knock that further frustrated Australia's attack.
An attempt to heave Josh Hazlewood to leg ended the entertaining cameo, with last man Ngidi then run out by Smith's direct hit trying to pinch a second run.
Still, South Africa's last three wickets had added 155 runs in partnership with De Villiers, tilting a see-saw Test firmly in favour of the hosts.