Sri Lankan left-arm spinner Lasith Embuldeniya claimed a five-wicket haul on debut and sparked a South African collapse to give the visitors some sort of hope on Day 3 of the first Test in Durban.
Sri Lanka ended the day at 83/3 – with bad light forcing early stumps, needing 221 more runs for an unlikely victory.
Openers Dimuth Karunaratne (20) and Lahiru Thirimanne (21) started the chase well with a 42-run opening partnership but departed within four deliveries of each other.
Rabada removed Thirimanne as he went for an expansive drive but could only manage an outside edge to Faf du Plessis who took a good diving catch. In the very next over, Philander got one to come back in sharply and get Karunaratne lbw.
Duanne Olivier accounted for Kusal Mendis for a duck, as he nicked one to the keeper. However, Oshada Fernando and Kusal Perera stitched an unbeaten 31-run partnership to keep the visitors in the game. It will require a big effort if Sri Lanka are to cross the finish line in this one, perhaps something similar to debutant Embuldeniya effort early in the day.
He took five for 66 as South Africa were bowled out for 259 in their second innings.
South Africa were on course to set the tourists a more challenging target when they reached 251 for five, with du Plessis and Vernon Philander looking solid in a sixth wicket partnership of 60.
But Embuldeniya, who bowled with impressive control, bowled Philander to start a collapse in which the last five wickets fell for eight runs.
Left-arm swing bowler Vishwa Fernando dismissed Du Plessis for 90 three overs later and the rest of the batting crumbled.
Fernando took four for 71 to follow up a career-best four for 62 in the first innings.
Du Plessis played a solid innings, facing 182 balls and hitting 11 fours before he padded up to a ball from Fernando which swung in and trapped him palpably in front of his stumps.
Du Plessis and Quinton de Kock (55) put on 96 for the fifth wicket. De Kock was in sparkling form in a 62-ball innings before he went back on his stumps to Embuldeniya and was leg before to a ball which spun in to the left-hander and kept low.