Spinner Mitchell Santner had the last man Naseem Shah caught and bowled with just 4.3 overs left in Mount Maunganui.
The tourists began 71-3 need to bat out the day for a draw or score 373 to win, and Fawad Alam hit 102, sharing a 63.2-over stand with Mohammad Rizwan.
Rizwan fell with 25 overs left before the hosts took the final five wickets.
“It was a brilliant game,” New Zealand captain Kane Williamson express.
“Both teams put their best foot forward and Pakistan were incredibly resilient in that second innings, but the boys kept coming.
“A huge effort by the bowlers to get us across the line.”
“I just told him he’s mad,” said Rizwan, who was leading Pakistan with Babar Azam injured. “He’s a different guy. His attitude is everything, his aggression is very beautiful.”