Elgar moved to 128 at the close, having faced 262 balls. He hammered 28 fours. Temba Bavuma will resume with Elgar on 38 on the second day. The duo amassed 81 runs for the fifth wicket off 181 deliveries.
Elgar compiled his seventh test century, when he pulled a short delivery by Jimmy Neesham with disdain to the mid-wicket boundary to reach three figures off 197 balls, with 20 fours.
The left-handed batsman was offered a reprieve in the second over after lunch when BJ Watling dropped him on the leg-side off Trent Boult when on 36.
The experienced opener shared in a 126-run partnership for the fourth wicket with the captain, Faf du Plessis, who managed 52 off 118 balls with seven fours.
Bavuma joined Elgar and the two handled the five-man attack with aplomb.
Boult struck in the first half an hour when he trapped Stephen Cook in front for three with a ball that swung back late.
In the 19th over, the South African born seam bowler Neil Wagner produced a double-strike and had South Africa in sixes and sevens on 22 for three.