JP Duminy scored his fourth Test century and his first in the subcontinent to steer South Africa to a first innings total of 455 for nine wickets declared on the second day of the first Test against Sri Lanka in Galle.
At close, Sri Lanka openers Kaushal Silva and Upul Tharanga had survived 12 overs to take the hosts to 30 without loss.
Batting at number eight, Duminy completed his well-composed unbeaten 100, including 10 fours, with support from the tailenders.
Morne Morkel stayed at the crease for 74 balls, scoring a defiant 22, to help Duminy reach his hundred in a ninth-wicket stand of 66 runs.
The visitors batted to a plan to occupy the crease for as long as possible and wear out the pitch, using up just over 166 overs in their first innings.
The second and final Test is next week in Colombo.