Left-handed opener Kusal Perera hit a brilliant 40-ball 61 to lift Sri Lanka, who won the toss and batted, to 165-7 before restricting South Africa to 160-5.
The victory gave Sri Lanka an ideal start to the group one campaign in the Super-10 stage at Zahur Ahmed Chowdhury stadium.
South Africa needed 15 off the final over but Lasith Malinga kept a tight line and despite a last ball six by tail-ender Imran Tahir, Sri Lanka carried the day.
South Africa were given a flying 32-run start by Quinton de Kock (25) and Hashim Amla (23).
Jean-Paul Duminy (39) and AB De Villiers (24) hit Ajantha Mendis out of the attack with 22 runs in his first two overs but both departed within nine runs to give Sri Lanka the edge.
David Miller (19) and Albie Morkel (12) briefly threatened, with Morkel hitting two successive sixes but Sri Lanka pulled off the win.
Sri Lanka captain Dinesh Chandimal praised Perera and the death bowling.
"Everyone is over the moon," said Chandimal.
"I am f