Kusal Perera scored a 200-ball unbeaten 153 as the visitors sealed a one-wicket win in Durban.
Set a target of 304 to win, Sri Lanka were 83 for three when bad light brought a premature end to proceedings.
Dale Steyn grabs four as Proteas take advantage on second day of first Test.
Sri Lanka on top despite Quinton de Kock resistance in the opening day of the first Test at Durban on Wednesday.
South Africa were restricted to 141/9 with the returning Mohammad Amir picking up three wickets
South Africa hold nerve after Babar Azam 90 to seal series, end Pakistan world-record run of 11 straight Twenty20 series victories.