Opening batsman Elgar made 118 not out as South Africa were bowled out for 214 shortly before lunch.
Fast bowler Stuart Broad and off-spinner Moeen Ali both took four wickets in the innings.
Broad followed up his three wickets on the second day with an early breakthrough on Monday, bowling Temba Bavuma off an inside edge with the second ball of the morning, without addition to the overnight total of 137 for four. Broad had figures of four for 25.
Ali took two wickets in successive overs, dismissing JP Duminy and Kyle Abbott, as South Africa crashed to 156 for seven before Dale Steyn helped Elgar add 54 for the eighth wicket.
Ali ended the partnership shortly before the second new ball was due when Steyn lofted a catch to mid-off.
He bowled 12 overs in an unchanged spell during the morning, taking three wickets for 24 runs for innings figures of four for 69.
Steven Finn wrapped up the innings, taking the last two wickets in the space of four balls in the second over with the new ball.
The left-handed Elgar batted resolutely while his teammates struggled, reaching his fourth Test century off 211 balls, with eight fours and a six.
He did not add to his boundary count before running out of partners after facing 246 deliveries.