The second Test between Sri Lanka and South Africa in Colombo looks set for a thrilling conclusion on Monday.
Heading into the fifth day, the tourists need 331 more runs with nine wickets in hand off a minimum 98 overs to win the game.
South Africa were 38-1 at stumps in their second innings on the fourth day, with Quinton de Kock unbeaten on 21 alongside Dean Elgar on 13.
Sri Lanka's Rangana Herath picked up an early wicket to put South Africa under pressure after the visitors were set 369 to win.
Opening the bowling, the left-arm spinner had opener Alviro Petersen caught by Kithruwan Vithanage without scoring with the total on four. De Kock and Elgar subsequently accepted a bad light offer and left the field.
Sri Lanka earlier declared its second innings on 229-8, with Morne Morkel returning 4-45 for South Africa.
Sri Lanka made 421 in the first innings and dismissed South Africa for 282.
The Proteas lead the two-Test series 1-0 after winning the opener in Galle by 153 runs.