Elgar dominated both pace and spin bowling to smash 11 fours and three sixes during his 187-ball knock and was supported well by Faf du Plessis, who struck a fine 80 coming in at No.3.
Elgar batted just over two sessions and hit three sixes and 11 fours to bring up his second Test century.
However, the hosts hit back in the final session with four wickets as South Africa suffered a middle-order slump.
The left-handed Elgar seized the early initiative with free strokes against the seam bowlers and good use of the feet against spinners.
More From This Section
Elgar and de Plessis were not afraid to go for the shots and also rotated the strike well in what was the fourth century partnership between them.
The pair added 125 runs for the second wicket after Elgar and Alviro Petersen had put on 70 in their opening stand.
Elgar got to the three-figure mark with a six to long-on off off-spinner Dilruwan Perera to move from 96 to 102 after batting cautiously earlier in the 90s.