Colombo: Hashim Amla led South Africa's recovery to 98 for 3 in reply to Sri Lanka posting 421 on day two of the second cricket Test on Friday.
Mahela Jayawardene was run out for 165 on his home ground at Sinhalese Sports Club, hastening a Sri Lanka collapse from 385 for 5.
Sri Lanka removed both South Africa openers within nine overs, but captain Amla held firm to reach stumps on 46 not out off 134 balls, with AB de Villiers on 11. South Africa trailed by 323 runs on the first innings.
With Sri Lanka playing three specialist spinners, Rangana Herath and Dilruwan Perera claimed wickets in their first overs. Herath came into the attack in the second over of the South Africa innings and accounted for Alviro Petersen on 2, while Perera came in as first change in the sixth over and had Dean Elgar caught at short leg by Kaushal Silva for 1.
Amla and Francois du Plessis added 58 runs off 30 overs before du Plessis was spectacularly caught by a diving Niroshan Dickwella down the leg side. The Sri Lanka wicketkeeper has been making a heady debut, having rushed from England where he was playing for Sri Lanka A.
Earlier, he contributed with the bat, adding 100 runs for the sixth wicket with the retiring Jayawardene.
Jayawardene, who came to bat at 16 for 2 on Thursday, was finally dismissed midway through the first session. He was run out attempting a second run after playing a sweep shot to fine leg. He batted for more than seven hours for his 34th Test hundred and 11th at SSC, and hit 17 fours and a six off 284 deliveries.
This is his second-to-last Test series, which Sri Lanka was hoping to square after losing the first Test in Galle by 153 runs.
Dickwella was also run out when he chanced wicketkeeper Quinton de Kock's arm. He made 72. He faced 116 deliveries and hit eight fours and a six.
Sri Lanka lost its last five wickets for 36 runs, as Dale Steyn, Vernon Philander and JP Duminy all finished with two wickets apiece.
But some tight bowling by the Sri Lanka spinners brought them back into the game, as South Africa scored less than two runs an over.