On a turning surface at Galle, it was fast bowler Kagiso Rabada who did the maximum damage for the touring side with four wickets for 50.
Left-arm wristspinner Tabraiz Shamsi, playing only his second Test, returned figures of 3-91.
Former pace spearhead Dale Steyn, returning to the South African team from injury having last played a Test in January, picked up the wicket of Kusal Mendis for 24 to trigger a mini collapse.
Rabada removed former captain Angelo Mathews and Roshen Silva in the same over as the hosts lost three wickets for four runs to be left reeling at 119-5.
Experienced Karunaratne, back to open the batting for the hosts after missing the West Indies tour due to injury, stitched together meaningful stands with Niroshan Dickwella, who made 18, and Lakshan Sandakan, the duo adding 63 for the last wicket.