De Villiers (89 not out) combined with J P Duminy (58 not out) in an efficient 139-run partnership after a tight and varied New Zealand bowling attack had given the hosts the sniff of an unlikely victory when they reduced them to 97 for four in the 25th over at Bay Oval in Mount Maunganui.
The 30-year-old De Villiers, however, completed his 39th ODI half-century, while Duminy compiled his 20th and hit a six to win the game as they tourists finished on 236 for four, having chased New Zealand's 230.
The series is being used by both sides to finalise their selections for next year's World Cup in New Zealand and Australia.
New Zealand's batsmen, however, did little to showcase their credentials and their total was only boosted by a record 10th-wicket partnership of 74 between Luke Ronchi and Trent Boult which rescued them from 156 for nine.
Wicketkeeper Ronchi was agonisingly close to his first ODI century after reaching 99 on the final ball of the 45th over.
The 33-year-old, however, seemed in two minds on the next ball and only succeeded in giving wicketkeeper Quinton de Kock his fifth catch of the innings and sixth dismissal overall with the stumping of Tom Latham.
The innings by Ronchi, under pressure from test wicketkeeper BJ Watling for a place in the World Cup squad, showed coach Mike Hesson he could be the ideal player to close out New Zealand's innings after hitting three sixes and 11 other boundaries in his 83-ball stay.
Scorecard
New Zealand:
M. Guptill c de Kock b Philander 5
J. Neesham c de Kock b Philander 16
D. Brownlie c de Kock b Tahir 24
B. McCullum c Tahir b M. Morkel 16
T. Latham st de Kock b Duminy 29
C. Anderson b M. Morkel 0
L. Ronchi c de Kock b Steyn 99
D. Vettori lbw b Tahir 0
N. McCullum c de Kock b McLaren 6
K. Mills c Philander b McLaren 1
T. Boult not out 21
Extras: (lb-7, nb-1, w-5) 13
Total: (in 45.1 overs) 230
Fall of wickets: 1-21, 2-35, 3-68, 4-68, 5-68, 6-133, 7-134, 8-145, McCullum,9-156, 10-230.
Bowling: D. Steyn 7.1-1-28-1, V. Philander 7-1-38-2(w-2),M. Morkel 8-1-39-2(nb-1), I. Tahir 10-1-37-2, R. McLaren 8-0-59-2(w-2), J. Duminy 5-0-22-1(w-1).
South Africa:
Q. de Kock c Latham b Boult 9
H. Amla b Mills 38
F. du Plessis c Ronchi b Boult 8
R. Rossouw c Brownlie b Anderson 26
A. de Villiers not out 89
J. Duminy not out 58
Extras: (lb-3 nb-1 w-4) 8
Total: (for 4 wickets, 48.1 overs) 236
Fall of wickets: 1-11, 2-30, 3-73, 4-97.
Did not bat: R. McLaren, V. Philander, D. Steyn, M. Morkel, I. Tahir
Bowling: K. Mills 8.1-0-47-1, T. Boult 10-2-40-2(nb-1, w-3), D. Vettori 10-0-43-0, N. McCullum 10-0-45-0, C. Anderson 6-0-31-1(w-1), J. Neesham 4-0-27-0.
Result: South Africa won by 6 wickets
Image: JP Duminy celebrates with AB de Villiers after winning One-dat International match between New Zealand and South Africa at Bay Oval.
Photograph: Hannah Peters/Getty Images
Rankings: In-form Kohli displaces Amla to go 2nd; Bhuvneshwar breaks into top 10
Firms cut security spending despite breaches, says PwC survey
Kiwi Neesham gets opening responsibility, could answer Ryder quandary before WC
Team India look serious contenders to defend their World Cup title
Pistorius sentenced to five-year jail term for killing girlfriend