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.
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.
Left-armer Tsotsobe removed danger man Mahela Jayawardene and captain Dinesh 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.