A five-wicket haul from Dilruwan Perera helped Sri Lanka stay in control of South Africa on the third day of the second Test in Colombo.
The hosts dismissed the tourists for 282 and reached 11 without loss in their second innings for an overall advantage of 150 runs with two days remaining.
Perera was the pick of the home side's bowlers, taking 5-69, while Rangana Herath provided excellent support with 4-71.
South Africa were thankful to captain Hashim Amla for helping them stay in contention as the day's outstanding performer turned his overnight 46 not out into an unbeaten knock of 139.
The Proteas resumed the third morning on 98-3 and Amla and AB de Villiers added 52 before Perera started his onslaught, trapping De Villiers lbw for 37 and two balls later bowling Quinton de Kock.
JP Duminy had made a painstaking three when he was stumped by debutant wicketkeeper Niroshan Dickwella off the bowling of Herath - the 58th ball Duminy had faced - and it was 204-7 when Perera bowled Vernon Philander for nine.
Dale Steyn had contributed 30 to an eighth-wicket stand of 47 with Amla when he was caught by Kumar Sangakkara at long-off off the bowling of Herath.
And 251-8 became 279-9 when Imran Tahir became Herath's fourth victim of the innings when he was caught by Upul Tharanga at deep mid-off for 15.
The tourists' effort was over just two runs later, when Morne Morkel went first ball, caught at forward short-leg by Kaushal Silva to give Perera his five-wicket haul.
It all means the hosts are in a good position to level the two-match series, having lost the opener in Galle by 153 runs.