The three-wicket win in the rain-abridged match also wrapped up the series for New Zealand 2-0.
Initially set a target of 291 to win, New Zealand made a disastrous start with Brendon McCullum out for a first-ball duck.
But Guptill and Williamson restored order with a 159-run stand, a New Zealand ODI record for the second wicket, to set the side up before a lengthy rain delay shortened the match by seven overs.
With 27 balls remaining and New Zealand still 38 runs short of their target, Corey Anderson appeared to have been caught behind but was given not out and Pakistan had used up their review.
Also Read
The ODI series win added to New Zealand's golden summer after they also beat Pakistan 2-1 in the Twenty20s and beat Sri Lanka in Tests, ODIs and Twenty20s.
In the decider against Pakistan, Azhar Ali won the toss and opted to bat first which initially proved productive.
But they were soon to run out of steam with their last
six wickets falling for 63 runs and they were all out for 290 with 15 balls remaining.
McCullum's comeback was very brief after being sidelined for five weeks by a back complaint.
The first ball he faced from Mohammad Amir was hooked to long leg where Mohammad Irfan took a smart catch on the run.
Enter Williamson to partner Guptill in a record stand, two better than the previous best 157 which Guptill had set with McCullum four years ago against Zimbabwe.
Guptill was first to go for 82 caught at point by Hafeez, and Williamson was stumped for 84.
Azhar may consider himself a part-time bowler but showed all the guile of a career leg-spinner when he outwitted Williamson charging down the wicket by getting the ball through to wicketkeeper Sarfraz Ahmed.
Henry Nicholls, who set up the first ODI win, and Grant Elliott both fell cheaply as New Zealand slipped from 165-1 to 210-5.
Lusty hitting from Anderson with 35 off 29 narrowed the gap and with six required off the last over, Mitchell Santner hit boundaries off the first and fourth deliveries to get New Zealand home.