You are not permitted to download, save or email this image. Visit image gallery to purchase the image.
The Proteas, who came into the game having already lost the three-match series 2-0, had been set a target of 261 after half-centuries from Grant Elliott (54), Colin Munro (57) and James Franklin (53 not out) had steered New Zealand to 260 for nine in their 50 overs.
Man-of-the-match Smith's knock seemed to have put the home side on course for victory but a lower-order collapse meant they required three off the final delivery with just one wicket in hand.
However, a six over fine leg from all-rounder McLaren (25 not out) gave South Africa their first victory of the series and ensured they avoided a whitewash.
New Zealand had already claimed their first ODI series on South African soil but still went wholeheartedly for the final victory as they won the toss and elected to bat.
They made a slow start as a fine opening spell from left-arm seamer Lonwabo Tsotsobe (10-2-45-4) helped restrict them to 68 for four in the 22nd over.
The half-centuries from Elliott and Munro saw the Black Caps put on successive fifty partnerships and by the time both men had been dismissed, the visitors had recovered to 196 for six after 43 overs.
Despite a late flurry of wickets, Franklin came in and played with freedom. His undefeated innings was rounded off in style as he reached his fourth ODI fifty with a six in the final over from Rory Kleinveldt.
The South African reply made a brisk start as the left-handed opening duo of Smith and Quinton de Kock (31) took the score to 54 without loss after the first powerplay.
Franklin (6-0-38-2) made the breakthrough in the 16th over when he bowled de Kock but at 83 for one, the openers had laid a good platform for the home side.
Smith looked undeterred by the loss of his partner and later reached the fifty-mark in the 20th over.
He and Colin Ingram (25) then took the score to 122 by the end of the 26th over and it prompted the pair to take the batting powerplay.
The decision merely succeeded in yielding instant dividends for New Zealand though as Nathan McCullum (10-1-35-1) had Ingram caught at mid-wicket with the next delivery.
South Africa then showed signs of stuttering as the dismissals of captain Faf du Plessis (19) and Farhaan Behardien (4) reduced them to 174 for four.
Smith was not to be denied though and brought up his 10th ODI century with consecutive boundaries off Kane Williamson (8-0-40-2) in the 41st over.
But the dismissal of David Miller (15) in the following over triggered a collapse including the wicket of Smith, meaning South Africa needed eight off the final over with just two wickets in hand.
The Proteas required three off the final two deliveries and when Dale Steyn (4) was caught on the boundary, it was left to McLaren to get the hosts over the line.
The left-hander duly obliged as he dispatched the final delivery from Franklin (6-0-38-2) over fine leg for a dramatic six to the delight of the ecstatic crowd.