Off-spinner Akila Dananjaya picked up two early wickets to give Sri Lanka hope but the touring side, who were mauled 2-0 in the test series, recovered to reach the target in 31 overs and take a 1-0 lead in the five-match series.
Opener Quinton de Kock and captain Faf du Plessis hit identical 47s to steady South Africa’s chase during a 86-run stand for the third wicket before the wicketkeeper-batsman became Dananjaya’s third victim.
It was left to JP Duminy to take South Africa home with an unbeaten 53 off 32 deliveries.
Earlier, Kusal Perera hit a 72-ball 81 to provide some respectability to Sri Lanka’s innings after the hosts were reduced to 36-5 in the face of a devastating opening spell from Rabada.
Kusal and Thisara Perera, who made 49, added 92 for the sixth wicket during a counter-attacking partnership before Shamsi separated them by dismissing the latter, caught behind to wicketkeeper de Kock.
Shamsi also dismissed Kusal, who was out caught trying to play a reverse sweep, after an entertaining innings that included 11 fours and a six.
The second match of the series will be played at the same venue on Wednesday.