JP Duminy scored 30 off 23 balls and David Miller hit an aggressive 21-ball 36 as the Proteas reached 145-6 after electing to take first strike in the day-night match.
Fast bowlers Lonwabo Tsotsobe and Morne Morkel then claimed two wickets each as Sri Lanka, the world's top-ranked Twenty20 side, were restricted to 123-7 by an impressive South African fielding display.
Kumar Sangakkara played a lone hand for the hosts with an attractive 39 off 35 balls, but he was only one of three batsmen who crossed 30 in difficult conditions for both teams due to the stiff breeze.
The series win helped South Africa salvage pride after an embarrassing 4-1 defeat in the preceding one-day internationals.
South Africa's Twenty20 captain Faf du Plessis said the win was sweet revenge for that loss.
"Sri Lanka showed no mercy in the one-day internationals and we certainly don't want to be showing them any in the T20s," du Plessis said.
"The team has shown great character after what happened earlier. I thought we played a great game of cricket to get to 145 despite the wind. We were tactically very good in the bowling also."
The tourists, who won the first Twenty20 game by 12 runs in Colombo on Friday, will be looking to secure a series whitewash when the final match is played in Hambantota on Tuesday.
Sri Lanka, who will lose their number one ranking to second-placed Pakistan if they are defeated again on Tuesday, paid the price for poor batting.
"I think it was a gettable score, but we just did not bat well," said skipper Dinesh Chandimal.
"There were too many rash strokes. Hopefully we will do better and win on Tuesday."
Left-armer Tsotsobe removed danger man Mahela Jayawardene and Chandimal in his first three overs with both batsmen falling to catches by wicket-keeper Quinton de Kock.
Morkel claimed the vital wicket of Sangakkara, caught superbly in the covers by David Wiese, before having Nuwan Kulasekara caught behind.
Thisara Perera remained unbeaten on 22 off 20 balls as the South Africans fielded superbly to keep the runs in check.
Earlier, aggressive batting by Duminy and Miller helped the tourists recover after they were reduced to 48-3 in the ninth over.
The tourists were unchanged for the second game, while Sri Lanka brought in Jayawardene and Kulasekara in place of Tillakaratne Dilshan and Jeevan Mendis.
Seamer Kulasekara finished with two for 22, while Sachithra Senanayake claimed two for 18 in four steady overs of off-spin bowling.
Opener de Kock scored 19 and star batsman AB de Villiers was run out on 15. Also Read