The touring side, replying to the hosts’ 421 all out, trailed by 323 runs at the close on the second day with Hashim Amla unbeaten on 46 and AB de Villiers on 11.
Amla had two escapes on 10 and 34, edging a drive off Dilruwan Perera past Mahela Jayawardene’s outstretched hand at slip and then having his stumps shattered by Suranga Lakmal as he moved away from his crease when a crow flew across the pitch.
The bowler appealed to the umpire who signalled a dead ball.
Sri Lanka’s only success in the final session was the wicket of Faf du Plessis who was caught brilliantly down the leg side by wicketkeeper Niroshan Dickwella off Lakmal for 36 to end a partnership of 58 with Amla.
“The wicket is pretty nice to bat on but they got a pretty variety of spinners which don’t give much it’s tough to score against them because they put their fields to protect the boundary and got a few guys stopping the ones,” Du Plessis told reporters.
“You have to take a risk to score against them but as myself and Hash (Hashim Amla) showed if you get through the pressure of the first couple of balls the runs will come.”
Sri Lanka’s spinners had taken two early wickets to reduce South Africa to 23 for two at tea.
Left-armer Rangana Herath, who opened the bowling, struck with his fifth ball when he forced Alviro Petersen to hit back a tame return catch with his score on two.
Perera had Dean Elgar, on one, caught off the inside edge off his third ball by Kaushal Silva at short leg to leave South Africa in trouble on a turning pitch at 13 for two.
Sri Lanka’s innings ended with Vernon Philander picking up the last two wickets of Ajantha Mendis (2) and Lakmal (4) to catches by wicketkeeper Quinton de Kock.
Debutant Dickwella, whose innings of 72 came off 116 deliveries, was run out when he hesitated over a single to a ball that went off Herath’s shoulder and De Kock reacted quickly to throw the stumps down.
Leg-spinner Imran Tahir picked up his first wicket after conceding over 100 runs when he had Perera caught by Amla at mid-on for 12 attempting a big hit.
Jayawardene was run out for 165 as Sri Lanka piled on the runs on the second morning.
South Africa’s only success was the wicket of Jayawardene, who had passed 150 for the 16th time in his career before he was run out.
The elegant right-hander swept JP Duminy to fine leg and Petersen’s direct throw at the stumps caught the diving batsman well short of his ground.
His 165 came off 284 balls and included one six and 17 fours.
“Disappointed in Galle that I wasn’t able to contribute the first innings was where we made quite a few mistakes,” Jayawardene said.
“We needed to make sure that we didn’t repeat the mistakes here. The mind set was pretty positive to take control of the situation we were in.”
(Editing by Ed Osmond)