AB de Villiers hit a half-century on his return to international cricket, but it was not enough to prevent Sri Lanka from beating South Africa in the series-deciding third Twenty20 international at Newlands on Wednesday.
De Villiers made 63 off 44 balls in the Proteas' total of 5-169 but Sri Lanka won by five wickets with one ball to spare to regain some pride after being outplayed in the three-match Test series.
The win sealed Sri Lanka's first-ever series victory in South Africa in any format.
"I'm over the moon," said stand-in Sri Lanka captain Dinesh Chandimal. "After losing the Test series, I'm really happy with the way we played."
Opening batsman Niroshan Dickwella made 68 off 51 balls before Seekkuge Prasanna clinched a 2-1 series win for the tourists by slamming an unbeaten 37 off 16 deliveries.
Dickwella was handed both player-of-the-match and player-of-the-series honours after making useful contributions in all three T20 games.
South Africa dropped five catches - including three off successive balls in one over from Wayne Parnell - and were hampered by an injury to fast bowling discovery Lungi Ngidi, who left the field after bowling only two of his potential four overs.
Sri Lanka, though, could take pride in overcoming the loss of injured captain Angelo Mathews, who played a match-winning innings to level the series in the second match in Johannesburg last Sunday. "Angelo is a big part of this win," said Chandimal.
Quick Single: One-legged Mathews slogs Sri Lanka home
"It's a bitter pill to swallow," said South African captain Farhaan Behardien. "I thought we had enough runs on the board but the dropped catches put us on the back foot and losing Lungi Ngidi wasn't ideal."
Playing in his first international match after recovering from an elbow injury which kept him out of action for six months, De Villiers made a cautious start, with his first run coming off the fifth ball he faced.
His first six runs were singles but he gradually increased his range of strokes, hitting left-arm spinner Lakshan Sandakan for a straight six and pulling a short ball from Asela Gunaratne for another six as he went to his ninth T20 international fifty off 35 balls.
Quick Single: De Villiers smashes ton in cricket return
He cleared the boundary with another pull shot, off Isuru Udana, but he lost his wicket just as the hosts were looking to pile on the pressure when he squeezed a drive against Nuwan Kulasekera to Upul Tharanga at backward point off the first ball of the 18th over.
With Behardien having been run out three balls earlier, it meant South Africa lost two experienced, explosive batsmen in quick succession.
Mangaliso Mosehle hit three sixes in the final over, however, to enable South Africa to post a competitive total.
The left-handed Dickwella provided the foundation for Sri Lanka's win with a 71-run third-wicket stand with Dhananjaya de Silva.
Leg-spinner Imran Tahir dismissed both batsmen in the 16th over to give South Africa a chance before Prasanna's uninhibited hitting took Sri Lanka over the line.