South Africa 124 (du Plessis 48, Akila 5-52) and South Africa 139 for 5 (de Bruyn 45*) needs another 351 runs to beat Sri Lanka 338 (de Silva 60, Gunathilaka 57, Karunaratne 57, Maharaj 9-129) and 275 for 5 dec (Karunaratne 85, Mathews 71, Gunathilaka 61, Maharaj 3-154)
Colombo: Sri Lanka's formidable battery of tireless spinners bowled them to within five wickets of a 2-0 series sweep over South Africa as the tourists continued to struggle against the turning ball in the second and final test on Sunday.
Chasing an improbable target of 490 to level the series, the tourists finished day three on 139-5, their highest total in the spin-dominated series, at Colombo's Sinhalese Sports Club Ground.
At day's end, Theunis de Bruyn was batting after a gallant 45, showing the kind of application and positivity that were lacking in his colleagues while Temba Bavuma was on 14 at the other end.
Sri Lanka resumed day three on 151 for three, with an overall lead of 365 runs against a South African side who have yet to score 150 in the series, and decided to allow Angelo Mathews to bat himself into form.
The other overnight batsman Dimuth Karunaratne continued his strong run of form to score 85, his fourth 50-plus knock in as many innings, before falling to Lungi Ngidi.
Mathews made 71 before being dismissed by South Africa's left-arm spinner Keshav Maharaj who finished with a 12-wicket match haul.
Sri Lanka captain Suranga Lakmal soon declared on 275 for five, before unleashing his three-pronged spin attack who blew away the top half of the South African batting line-up.
Dilruwan Perera enjoyed an eventful 36th birthday as he first spilled Dean Elgar and then twice dismissed the opener off no-balls before the finally sending him back for 37.
Rangana Herath bowled Hashim Amla with his drift and turn and Akila Dananjaya struck double blows when he dismissed South Africa captain Faf du Plessis (seven) and the scoreless Maharaj off successive deliveries.
Lakmal, the lone paceman in the Sri Lanka attack, did not bowl himself in the first innings and has yet to roll his arm in the second as his spinners wreaked havoc against the leaden-footed South Africans.