Left-hander De Kock smashed a 127-ball 128 while skipper De Villiers hit a fiery 71-ball 108, making a century off just 66 balls, as South Africa posted their highest total against Sri Lanka of 339-5 in windy conditions at Mahinda Rajapaksa Stadium.
The Proteas then restricted the hosts to 257 in 44.3 overs for their first-ever one-day series win on the island by 2-1.
South Africa had won the first one-day in Colombo by 75 runs while Sri Lanka claimed the second by 87 at Pallekele.
When Lahiru Thirimanne went for 22 to make it 151-5, Angelo Mathews (58) and Ashan Priyanjan (30) put up some resistance during their 83-run stand but the target proved too much for the hosts.
Also Read
For South Africa paceman Ryan McLaren took 3-37 while Jean-Paul Duminy and Morne Morkel grabbed two wickets apiece.
"I am very happy over the win," he said. "It's our first series win here so we will celebrate it tonight."
Sri Lanka skipper Mathews was left to rue missed chances.
"It was very depressing," said Mathews. "We were pretty flat on the field, let go a few chances and didn't bowl well so we didn't deserve to win.