South Africa's Faf du Plessis smashed a career-best 185 off 141 balls as the hosts beat Sri Lanka by 40 runs after surviving a fierce onslaught in a high-scoring fourth one-day international to take a 4-0 series lead on Tuesday.
After opting to bat, South Africa posted 367 for five in their 50 overs at Newlands but were then put under pressure by the tourists who made a magnificent start, only to wilt at the death to finish on 327 all out with nine balls remaining.
Sri Lanka captain Upal Tharanga led their charge with a brilliant 119 from 90 balls but the home side clawed their way back as they built up the pressure and wickets began to fall.
South Africa head into the final fixture of the five-game series in Pretoria on Friday looking for a clean sweep to extend their 13-match winning run at home.
The hosts' innings was anchored by the magnificent century from Du Plessis, the highest ODI score at Newlands and three runs shy of South Africa's 50-over record of 188 scored by Gary Kirsten against the United Arab Emirates in the 1996 World Cup.
Du Plessis was well supported by Quinton de Kock (55 from 46 balls) and AB de Villiers (64 from 62) before a tired swipe to long-on off seamer Lahiru Madushanka saw him lose his wicket.
Du Plessis's stand of 137 for the third wicket with De Villiers from one ball shy of 20 overs laid the platform for what became South Africa's record ODI total at Newlands.
Sri Lanka made a thrilling start to their reply, crashing 100 without loss off the first 10 overs of their innings.
Tharanga and the classy Niroshan Dickwella (58 from 47 balls) added 139 in 16 overs before the latter was dismissed.
Tharanga carried on his merry way, crashing 11 fours and seven sixes, and when he was the third man out with the score on 216 in the 30th over, Sri Lanka were still in the driving seat.
But as South Africa began to find dot balls, Sri Lanka slipped from 307 for four to lose their final six wickets for the addition of only 20 runs.
Seamer Wayne Parnell was the pick of the home bowlers, returning figures of 4-58 in 9.1 overs, with one of those wickets the crucial scalp of Tharanga.