Malan fell early, but de Kock looked ominous as ever, looking fluent from the outset.
India, however, struck back with quick wickets with Deepak Chahar picking two wickets in the powerplay.
After SA were 3 down early, de Kock joined hands with Rassie van der Dussen to revive the innings.
De Kock followed up his fifty from the last game with a century in this before being dismissed for 124.
Rassie van der Dussen and de Kock added 144 for the fourth wicket before both were dismissed in successive overs.
South Africa lost their last 7 wickets for 73 runs as India restricted them to 287 in 49.5 overs.
Ngidi eked the outside edge off KL Rahul's bat in the fifth over.
Kohli and Dhawan kept the hosts at bay with a fifty-run stand to keep the chase on track with a 98-run stand.
Dhawan and Pant fell in the same over, but Kohli kept India in the chase getting to his fifty before falling for 65.
South Africa fought back with quick wickets and it looked like they would keep India at bay and pick up a comfortable win.
Deepak Chahar, however, had different ideas. He smashed a 34-ball 54 to put India in the driver's seat before falling in the 48th over.
With the equation coming down to 6 needed off 6, South Africa bowled India out to pick up a 4-run win to whitewash the visitors and win the series 3-0.