At the close on the second day in Adelaide, the Australians were 307 for six in reply to the Proteas' 259 for nine declared, with Khawaja unbeaten on 138 off 285 balls and Mitchell Starc not out 16. The home side lead by 48 runs.
It was Khawaja's fifth Test century and arguably his best as Australia seek to prevent the Proteas from an unprecedented series clean sweep after huge defeats in the opening two Tests.
It was the first century by an Australian in the series and the stylish left-hander has now scored 307 runs in the three Tests.
But his well-crafted ton was marred by a mix-up which left skipper Steve Smith stranded as he darted off for a quick single.
Also Read
Smith, who was put down by Hashim Amla on 46, was sailing along when his run out for 59 came out of the blue in a bad breakdown in communication with Khawaja.
Smith put on 137 for the third wicket in his 158 minutes at the crease and his dismissal summoned debutant Handscomb to the wicket.
Khawaja and Handscomb strengthened Australia's grip before Kyle Abbott got one through the debutant's defences on 54.
Handscomb looked comfortable in his 78-ball stay, hitting six fours, including three successive boundaries off Vernon Philander to reach his maiden Test half-century.
The South African bowlers laboured to make a breakthrough for the first time in the series as Australia's batsmen finally put up a resistance after several humiliating batting collapses.
Skipper Faf du Plessis used a total of seven bowlers in a bid to stop the Australian momentum, before taking the second new ball.
Recalled wicketkeeper Matthew Wade lasted just six balls for four, but Starc stayed at the crease with Khawaja in the day's final overs.
The Proteas struck twice with the wickets of English-born newcomer Matt Renshaw and David Warner inside the first hour.
Abbott enticed an edge and Elgar dived across second slip to take the catch just above the ground and send the youngster on his way.
Abbott prised the key wicket of Warner for 11 in his eighth over, getting the Australian vice-captain to edge to Elgar for his second catch.
Disclaimer: No Business Standard Journalist was involved in creation of this content