Rangana Herath struck twice late in the morning session to dent South Africa's fightback led by an unbeaten half-century by Theunis de Bruyn on day four of the second Test on Monday.
South Africa, chasing 490 to win, were 246 for seven at lunch with De Bruyn batting on 85 in Colombo. The visitors need another 244 runs to avoid their first series whitewash since 2006 when they lost 2-0 in Sri Lanka.
De Bruyn recorded South Africa's first fifty of the series early in the morning session and Temba Bavuma, who made 63, followed his overnight partner as the duo put on 123 runs.
Bavuma's resistance ended just after he was caught behind off Herath, who also got wicketkeeper-batsman Quinton de Kock lbw for eight on the stroke of lunch.
De Bruyn and Bavuma kept the spinners at bay for most part of the session after the visitors started the day on 139 for five.
De Bruyn was especially impressive, sweeping judiciously and defending doggedly on a tough surface, while Bavuma was also adept at picking gaps on the legside and rotating the strike.
De Bruyn will only have tailenders to bat with when play resumes after lunch and Sri Lanka will also be buoyed by the fact that the second new ball is due in 4.1 overs.