Johannesburg: Usman Khawaja (65) and Ricky Ponting (54*) were involved in a solid 100+ run partnership before Tahir struck to dismiss Khawaja. Bad light stopped play soon after. Aus were 142/3 at stumps.
Opening bowler Vernon Philander dismissed both Australia's opening batsmen as the tourists started their pursuit of a victory target of 310.
Earlier, the 18-year-old fast bowler took six for 77 to become the youngest player to take five or more wickets in his first Test.
But Cummins' effort was undermined when Shane Watson padded up to the second ball of Australia's innings and had his off stump knocked back by Philander.
Two overs later Phil Hughes edged Philander to second slip and Australia were 19 for two.
Usman Khawaja (26 not out) and Ricky Ponting (23 not out) added 45 more runs before tea, with Ponting reaching double figures for the first time in the series.
Cummins produced a high-quality display. He made the first breakthrough in the South African innings when he dismissed Jacques Rudolph on Saturday, then won a duel with South Africa's star batsman Jacques Kallis.
He again made a crucial early strike on Sunday when he had AB de Villiers caught at second slip to end a 147-run fourth wicket stand between De Villiers and Hashim Amla.
South Africa lost four wickets for 37 runs at the start of Sunday's play before an eighth wicket stand of 48 between Philander and Dale Steyn stretched their lead.
Again it was Cummins who produced for Australia, bowling a brutal bouncer with the first ball after lunch which Philander gloved to wicketkeeper Brad Haddin.
He yorked Morne Morkel with his next delivery. Steyn had a successful slog, hitting sixes off Peter Siddle and Cummins before Cummins finished the innings by having Steyn caught behind for 41, ending a last wicket stand of 25 which took the lead beyond 300.
Amla top-scored for South Africa, taking his overnight 89 to 105 - his 14th and second of the test match - before he was caught behind off Mitchell Johnson - his only wicket of the innings.
Brief scores
South Africa 266 & 339 (Amla 105, de Villiers 73, Cummins 6-79)
Australia 296 & 142 for 3 (Khawaja 65, Ponting 54*)
Status Australia need 168 runs to win with 7 wickets remaining