Kane Williamson and BJ Watling's Test record sixth-wicket partnership on day four hauled the Kiwis back into the match, having trailed by 135 on first innings in Wellington.
Mark Craig took 4-53 as the hosts bowled out Sri Lanka for 196.
"The last little while we've played some outstanding cricket," said New Zealand captain Brendon McCullum.
New Zealand have not lost a Test series since being beaten in England in May 2013.
Since then, the Black Caps have beaten West Indies home and away, overcome India and Sri Lanka at home, and drawn away series with Bangladesh and Pakistan.
Resuming on 45-1 in pursuit of an improbable 390 for victory, Sri Lanka slipped to 110-5 by lunch, and New Zealand wrapped up victory with a session to spare.
McCullum added: "To be able to fight our way out of an incredibly precarious position and not just save the Test, but to go on and win it in the manner that we did is testament to the work these guys do off the field."
The sides start a seven-match one-day series on 11 January in Christchurch.
New Zealand completed a fine comeback to beat Sri Lanka by 193 runs and win the two-Test series 2-0.