Cape Town: A career-best innings by Faf du Plessis trumped a thrilling century of Upul Tharanga as South Africa beat Sri Lanka by 40 runs in the fourth one-day international at Newlands on Tuesday.
Du Plessis hit 185, only three short of the South African ODI record, as South Africa piled up 367 for five.
It seemed as though Sri Lanka, who had been outplayed in the first three matches, would be on the end of another crushing defeat.
But Sri Lankan captain Tharanga hit a magnificent 119 off 90 balls and led his team's most spirited showing of the series. They were in with a chance of winning until a late slide in which they lost their last six wickets for 20 runs in 4.3 overs to be bowled out for 327.
Tharanga and fellow left-hander Niroshan Dickwella thrashed 100 runs in the first 10 overs on the way to a first-wicket partnership of 139 off 98 balls before Dickwella was caught on the midwicket boundary off Dwaine Pretorius for 58 off 47 deliveries.
Kusal Mendis (29) helped Tharanga add 64 for the second wicket as Sri Lanka stayed comfortably ahead of the required run rate until Wayne Parnell dismissed both batsmen. Tharanga, who was caught at backward point, hit 11 fours and seven sixes and left the field to a standing ovation.
Earlier, South Africa took full advantage of good batting conditions winning the toss.
Du Plessis made his runs off 141 balls and hit 16 fours and three sixes. He was caught at long-on off the first ball of the last over trying to clear the boundary with a hit which would have taken him past Gary Kirsten's long-standing South African best of 188 not out, made against the United Arab Emirates during the 1996 World Cup in Rawalpindi.
Du Plessis shared century partnerships with Quinton de Kock (55) and De Villiers (64).
Sri Lankan hopes flickered briefly when Hashim Amla was caught at first slip off Lahiru Kumara for one and South Africa were able to score only four runs in the first three overs.
But Du Plessis and De Kock quickly gained control, with the left-handed De Kock finding form for the first time in the series, reaching a half-century off only 40 balls as he and Du Plessis put on 100 off 87 balls for the second wicket
De Kock hit seven fours and two sixes in his 46-ball innings before he was caught at slip off left-arm spinner Sachith Pathirana.
Du Plessis and De Villiers added 137 off 122 balls for the third wicket before De Villiers missed a sweep against Pathirana and was bowled for 64 off 62 balls. He hit four fours.
Pathirana was Sri Lanka's most successful bowler, taking two for 55 and conceding only two boundaries in his 10 overs.
Brief scores
South Africa - 367 for 5 (du Plessis 185, Pathirana 2-55)
Sri Lanka - 327 (Tharanga 119, Dickwella 58, Weerakkody 58, Parnell 4-58)
Result - South Africa won by 40 runs