Dean Elgar posted a century as South Africa made a positive start on day one of the first Test against Sri Lanka at Galle before losing some momentum towards the close of play.
The tourists had reached 195 for the loss of only one wicket when Elgar, who hit 11 fours and three sixes in a knock of 103, was dismissed.
But they subsequently finished Wednesday's final session on 268 for five, with Dilruwan Perera and Suranga Lakmal claiming two wickets apiece.
Faf du Plessis contributed 80 to the South African effort, while Hashim Amla - in his first innings since being named as his country's new Test captain - could only manage 11 before being ousted.
Amla had earlier won the toss and after his side took to the crease, Alviro Petersen (34) and Elgar produced a first-wicket stand of 70 that was concluded when the former was trapped lbw by Perera.
Du Plessis came in and helped guide the Proteas to 111 for one at lunch, then survived a review not long after the interval.
He went on to bring up his half-century and Elgar sealed what was his second Test ton - by hitting Perera for six - before tea, at which point South Africa were looking comfortable on 194 for one.
But having come out from the pavilion, Elgar was soon heading back in again as his edge off Lakmal was caught behind by Dinesh Chandimal.
While the Elgar-Du Plessis partnership had yielded 125 runs, the latter's combination with Amla amounted to just 25.
The skipper lasted for 36 balls, being caught by Perera at mid-off via a Rangana Herath delivery to leave South Africa on 220 for three.
After Amla's replacement AB de Villiers just got back to his crease in time to avoid a stumping, Du Plessis - having struck five fours and a six - was seen off, caught smartly by Kaushal Silva at short leg off Perera, making it 246 for four.
The final wicket of the day came in the penultimate over when De Villiers, who had just seen an on-field decision to dismiss him overturned on review, was bowled for 21 by Lakmal.
Quinton de Kock and Dale Steyn were the men in the middle at stumps, on 17 and nought respectively.