South Africa were 121 for four at lunch, a lead of 254, with Amla unbeaten on 50.
Anderson struck twice in three balls in the fifth over of the morning, having Stephen Cook caught behind for 25, then trapping South African captain AB de Villiers leg before wicket for his second duck of the match.
At that stage South Africa were 49 for three, a lead of 182.
Anderson, whose four wickets in the first six innings of the series had cost 63.50 runs each, had a superb first spell of the day, taking two for seven in six overs. He bowled a tight line and length and swung the ball both ways.
Conditions remained tricky for batsmen on a cracked pitch with uneven bounce. Amla reached his half-century off 112 balls when he gloved a delivery from Stokes to leg which rose sharply off a good length.
