Big knocks from Dilshan and Thisara Perera lifted the visitors to 304-5 after the home side reached to 299-7.
Kimberley: Sri Lanka celebrated a rare success on Friday on their tour of South Africa with a five-wicket victory in the fourth one-day international.
Big knocks from captain Tillakaratne Dilshan (87), Man-of-the-Match Thisara Perera (69) and Dinesh Chandimal (59) lifted the visitors to 304-5 after the home side reached to 299-7 with skipper AB de Villiers (96) to the fore.
After keeping close to the six-run-an-over target at the De Beers Diamond Oval for much of the innings, the Sri Lankan batsman hit out against a South African attack sorely missing rested fast bowler Dale Steyn.
Unfortunately, the win came too late for the tourists to effect the five-match series, with the Proteas taking a winning 3-0 lead three days ago thanks to a four-run win in Bloemfontein.
"This was a fantastic effort as we were hoping to restrict South Africa to 250 or 260 runs," said Dilshan, "And on a personal note it was nice getting a big score again."
Dilshan averaged a run a ball in a 112-minute stand that included nine fours and two sixes, while Perera was even quicker, taking just 44 balls with three fours and five sixes.
Before the ODI matches began Sri Lanka lost a Test series 2-1, prompting the government to order a probe into a "crisis situation" after losses to England, Australia and Pakistan as well.
De Villiers hit eight fours and three sixes off 76 balls before being bowled by Perera with the ball slamming into middle stump after an attempt to steer it down leg side backfired. Graeme Smith returned to form with 68 runs after managing only six, 28 and two in the first three matches of the series, triggering a media and public outcry that led to De Villiers coming out in support of the Test captain. He struck seven fours and a six off 69 balls in the northern Cape city before being caught by Dilshan off the bowling of Lasith Malinga.
His dismissal 23.5 overs into the innings was soft, with the bat turning in his hand as he attempted a leg-side shot off a delivery that was short of a length.
De Villiers won the toss and opted to bat as South Africa sought a 4-0 lead over the visitors ahead of the final match in Johannesburg, and they put 84 runs on the board before Alviro Petersen (37) was first to fall.
Colin Ingram was trapped leg before just four balls after the departure of Smith, but Sri Lankan hopes of wresting the initiative were dashed as De Villiers and JP Duminy (36) added 70 fourth-wicket runs.