South Africa have set Sri Lanka a target of 340 in the third and final one-day international at Hambantota.
After winning the toss, Hashim Amla and Quinton de Kock put on 118 for the opening wicket before Amla was dismissed for 48 by Rangana Herath.
The wicket of Jacques Kallis quickly followed, but De Kock and AB de Villiers found their stride to ensure that the tourists took control of the innings.
After taking the score past 240 with 10 overs remaining, De Kock was finally dismissed for 128 after hitting 12 fours and three sixes, before JP Duminy added 29 off 24 balls.
However, it was De Villiers who took centre stage in the closing overs, taking his individual score to 108 off 71 deliveries before Ajantha Mendis struck, and South Africa will be confident that their mammoth total will be enough to win the series.