Mitchell Starc once again starred to put Australia on the brink of victory over South Africa in the first Test, despite a battling century from Aiden Markram.

South Africa were set a hugely imposing target of 417 after they polished off Australia's second innings by dismissing Pat Cummins early on day four.

It looked as if the Proteas would slip to a humiliating loss as they were quickly reduced to 49-4, only for Markram to provide at least a glimmer of hope with a hard-fought 143.

Markram's century marked the third of his career, but when he was caught behind off Mitchell Marsh to end a 218-ball knock, South Africa collapsed.

And it was unsurprisingly Starc who ripped through the tail, taking 4-74 after posting figures of 5-34 in the first innings, South Africa managing to survive the day on 293-9 as bad light stopped play.

Cummins dragged onto his stumps to end Australia's innings on 227 and the chase appeared set to be a brief one, the majority of the top order falling in short order.

Dean Elgar, batting despite dislocating his finger, scored just nine before Hashim Amla (8) was trapped lbw by Josh Hazlewood and AB de Villiers was run out at the non striker's end after a mix-up with Markram.

Faf du Plessis added a sole boundary before being skittled by Cummins, but Markram remained a constant and built partnerships that indicated an Australia win was perhaps not an inevitability.

He combined for 87 with Theunis de Bruyn, whose 36 comprised of six boundaries, but the stand that offered the most hope of a remarkable victory was the 147-run union he shared with Quinton de Kock (81 not out).

A gritty ton was brought up in undignified fashion, Markram diving in for a quick single before De Kock reached fifty in more aesthetically pleasing style, caressing the first of back-to-back boundaries through the gap.

However, Markram's commendable show of resistance was ended by Marsh and a well-taken Tim Paine catch after 340 minutes at the crease, with an incredible over from Starc that featured three wickets in five balls then putting Australia within a wicket of a 1-0 lead.

Starc drew a thin edge from Vernon Philander and then shattered the stumps of Keshav Mahraj and Kagiso Rabada in successive deliveries, De Kock and number 11 Morne Morkel surviving before being rescued by the fading light still 124 runs adrift of the target.