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.
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.
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.
(This story has not been edited by Business Standard staff and is auto-generated from a syndicated feed.)