A career-best 185 by Faf du Plessis inspired South Africa to a 13th consecutive home win and kept them on course for a one-day international whitewash of Sri Lanka.
Du Plessis made the Proteas' second-highest ODI score to set up a match-winning total of 367-5 at Newlands in Cape Town. His previous best in the format was 133 not out versus India in Mumbai during 2015 and his highest career score was 176.
Skipper Upul Tharanga gave the tourists hope of victory with 119 at the top of the order, but they succumbed to a 40-run defeat to go 4-0 down with one to play.
After the early loss of Hashim Amla - Du Plessis shared century stands with Quinton de Kock (55) and captain AB de Villiers (64), who registered his 50th ODI fifty.
The No 3, who also hit a hundred in the second ODI, holed out off Lahiru Madushanka in the last over of the innings, having struck 16 fours and three sixes from 141 balls.
In reply Tharanga and Niroshan Dickwella (58) shared 139 for the first wicket before Sandun Weerakkody (58) and Asela Gunaratne (38) kept Sri Lanka in contention, only for the tourists to slip from 307-4 to 327 all out in the 49th over.
Tharanga's side had to be content with passing 300 for the first time against South Africa on a mainly disappointing tour that started with a 3-0 Test series loss but picked up with a 2-1 Twenty20 series win.