Sri Lanka had lost 11 previous one day games against South Africa stretching back to their last win in 2014 at the same Pallekele ground
Suranga Lakmal took three key wickets in a tense encounter Wednesday cut short by rain to guide Sri Lanka to their first one-day win over South Africa in 12 matches.
Dasun Shanaka hit 65 while Thisara Perera and Kusal Perera each made 51 as Sri Lanka blasted 306-7 off 39 overs. Set a target of 191 from 21 overs because of the bad weather, South Africa ran out of inspiration and finished on 187-9.
Lakmal bowled South Africa's stand-in captain and opener Quinton de Kock, and then at the climax of the game claimed the tourists' final batting hopes Willem Mulder and David Miller.
Sri Lanka had lost 11 previous one day games against South Africa stretching back to their last win in 2014 at the same Pallekele ground.
South Africa already had the series sealed by winning the first three one-day games on this tour. But de Kock was still disappointed in his first match in place of captain Faf du Plessis who has been ruled out with a shoulder injury.
"They kept picking up wickets at the right time and bowled well," he said. "It always hurts more when you lose as captain."
De Kock passed 4,000 runs in one day internationals with a four in the second over before the rain came and South Africa's 39 overs were cut to 21.
Hashim Amla hit a 40 with six fours and Jean-Paul Duminy smashed two sixes and three fours as South Africa seemed to be heading for a fourth straight win in this series.
But Shanaka brilliantly ran out Duminy with a direct hit throw and Sri Lankan captain Angelo Mathews pulled off a brilliant catch to send back Heinrich Klaasen.
Mulder also fell to a spectacular diving catch by Dhananjaya de Silva.
South Africa's batting threat ended when Miller went for 21 and Lakmal made no mistakes keeping the lid on tail enders Junior Dala and Lungi Ngidi for the final five balls.
"It was very important to win today," said a relieved Mathews.
"The batters put up a decent score on a good pitch to bat on, it was a fantastic effort by the bowlers as well."
For Sri Lanka, Shanaka hit five sixes and four fours to anchor the innings.
Thisara Perera made an unbeaten 51 and Kusal Perera also hit 51 as the home side punished South Africa's bowlers.
The final game is in Colombo on Sunday.