South Africa were 263 for seven at the close, a lead of 20 runs after Australia were bowled out for 243 in their first innings.
There was a flurry of wickets after tea but De Villiers counter-attacked to hit 74 not out off 81 balls with easily the most aggressive batting of an otherwise slow day.
South Africa's quest for a series-levelling win was given added impetus by a pending disciplinary hearing which could result in fast bowler Kagiso Rabada being banned for the remaining two Tests after his shoulder made contact with Australian captain Steve Smith on Friday.
But the scoring was painfully slow and Australia were right back in the game when both batsmen were dismissed in the first two overs after tea, followed by two more batsmen being dismissed cheaply.
More From This Section
The Australian bowlers made effective use of reverse swing, firstly to restrict the scoring and then as a weapon in all four wickets.
Amla was bowled by a fast, reverse swinging yorker from Mitchell Starc for 56 four balls after tea and Elgar was caught behind off Josh Hazlewood for 57 in the next over. Like Amla, Elgar fell to a full delivery which swung late.
De Villiers and Quinton de Kock put on 44 for the seventh wicket before De Kock was bowled by off-spinner Nathan Lyon with a ball which spun sharply past the outside edge of his bat.
While other batsmen had struggled to gain any momentum to the South African innings, De Villiers looked at ease and played strokes to all parts of the ground in reaching a half-century off 62 balls with ten fours. By the close he had faced 81 balls and hit 14 boundaries.
Only 43 runs were scored in 26 overs between lunch and tea after a slightly less pedestrian morning during which 71 runs were scored in 28 overs.
Opening batsman Elgar, renowned for his gritty defensive qualities, was even slower than usual, taking 164 balls to reach his fifty. He was out for 57 after facing 197 deliveries and hitting six fours.
His only boundary during the afternoon came from an edge against Mitchell Marsh to raise his half-century.
Amla, normally more fluent, took 122 balls to reach fifty and went on to make 56 off 148 deliveries with six fours.