Babar Azam (83) and Mohammad Hafeez (76) laid the platform for a big total with a stand of 134 for the third wicket after Pakistan won the toss and opted to bat.
But the touring side, needing to win the match to tie the series at 1-1, suffered a mid-innings collapse to be shot out for 290 in the 48th over.
Brendon McCullum, returning from a back injury to lead the side, fell on the first delivery he faced from Mohammad Amir but Guptill (82) and Williamson (84) steadied the chase with their stand, the highest for the second wicket for the hosts.
Pakistan captain Azhar Ali dismissed both batsmen in quick succession with his part-time leg spin to bring his side back into the match and New Zealand were quickly reduced to 210-5.
But a rain interruption disrupted play and when New Zealand returned their target had been revised to 263 off 43 overs by the Duckworth-Lewis method.
All-rounder Corey Anderson (35) was given not out by umpire Billy Bowden off Rahat Ali after a confident appeal for caught behind and the powerful left-hander made most of his fortune by smashing the paceman for two sixes on the next two balls.
New Zealand, needing six to win off the last over, got over the mark with two balls to spare with Mitchell Santner hitting Wahab Riaz for two boundaries.
Earlier, Pakistan were comfortably placed on 215-3 in the 31st over, riding on half-centuries from Hafeez and Azam but lost their remaining seven wickets for just 75 runs to fall short of the target they would have liked to set New Zealand.
They would have folded for even less had wicketkeeper Sarfraz Ahmed not scored 41.
Adam Milne accounted for Pakistan's tail, picking up 3-49 while Trent Boult and Matt Henry picked up two wickets each.
Original source: NZ win rain-hit thriller, bag series