David Miller smashed an unbeaten 85 as South Africa beat Sri Lanka by 56 runs in Pallekele to stay alive in the five-match ODI series.
Miller's knock off 72 balls gave the tourists something to bowl at and Lonwabo Tsotsobe then ripped the Sri Lankan top order apart, recording figures of 4-22 as the Proteas bowled their hosts out for just 167 to win the third ODI with 40 balls to spare and reduce their deficit in the series to 2-1.
Only Thisara Perera, who blasted Robin Peterson for five sixes and a four off the 33rd over, provided any real resistance, but he could not prevent South Africa from registering the much-needed win, which ended an 11-match losing streak in one-day cricket on Sri Lankan soil.
Visiting skipper AB de Villiers opted to bat after winning the toss but his side got off to a dreadful start as they slumped to 53-3, Lasith Malinga accounting for Alviro Petersen and Perera dismissing both Quinton de Kock and JP Duminy inside the first 16 overs.
De Villiers' 47 helped to steady the ship before he was caught behind off Ajantha Mendis, the first of his three wickets for 35 runs, but it was then that Miller took up the challenge.
The 24-year-old smashed five sixes and four fours, scoring 35 off the last 10 balls as South Africa ended their innings on 223-7.
Sri Lanka's reply got off to a shaky start when opener Tillakaratne Dilshan spooned a mis-timed drive off Tsotsobe to de Villiers at extra cover and departed for six with just 14 on the board.
They slipped to 14-2 three balls later when Kumar Sangakkara went for a duck, Duminy taking the catch in the covers to hand Tsotsobe his second wicket of the over.
Upul Tharanga's involvement ended with only two more having been added when he edged Tsotsobe to first slip, and it took a dogged stand between Mahela Jayawardene and Dinesh Chandimal to put the Sri Lankans back on track.
However, Peterson broke the 55-run partnership when he clean bowled Jayawardene for 24 with an arm ball, and when Ryan McLaren nicked Chandimal to wicketkeeper De Kock on 29 and Angelo Perera and Angelo Matthews soon followed, Sri Lanka were reduced to 93-7.
But Perera gave his side hope with a brutal assault, hitting Petersen for five sixes and a four from the 33rd over, which also included a wide, to take the score to 129-7.
While he remained at the wicket Sri Lanka had a fighting chance, but once he had holed out to Faf du Plessis for 65 off Farhaan Behardian (3-19), the writing was on the wall and Malinga and Mendis failed to delay the inevitable.