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 and final Twenty20 international at Newlands on Wednesday.
De Villiers made 63 off 44 balls in a South African total of 169 for five but Sri Lanka won by five wickets with one ball to spare to regain some pride after being outplayed in a three-match Test series.
"I'm over the moon," said stand-in Sri Lankan 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 named man of the match and man of the series after making useful contributions in all three matches.
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.
"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.
He cleared the boundary with another pull shot, off Isuru Udana, but he lost his wicket just as South Africa 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 partnership with Dhananjaya de Silva. But 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.