The home team resumed after tea requiring just 86 more runs to win and with five wickets remaining, but the tourists fought back to secure an unlikely victory on a very flat deck as the sun began to set over the stadium.
England coach Brendon McCullum and captain Stokes did not deviate from their attacking and unconventional approach with both bat and ball and were rewarded with a first away win in 12 Tests on a pitch where just 14 wickets fell across all five days when Australia visited in March.
Stokes claimed it was one of his proudest achievements in an England shirt.
"I think it's probably one of the best," he said. "To be able to get a result on this type of wicket is mind-blowing and the effort that everyone has managed to put in this whole week is just incredible.
"I feel very honoured and I feel in a very privileged position to lead these lads out onto the field.
"Jimmy Anderson said to me before the match presentation that he was feeling quite emotional about this win - so to have a guy who has played 180 Test matches, who has experienced absolutely everything, to hear him say that about this Test match - I think that really makes you realise how special this week has been."
Jack Leach claimed the final wicket of Naseem Shah lbw following a lengthy rearguard effort from Pakistan for the final wicket, with all players surrounding the bat, including one on his knees in any attempt to wrangle a catch.
Spin bowler Leach said he felt like a "fraud" taking the final wicket - the only one to fall to spin in the fourth and final innings of the match.
On the winning moment, he said: "An unbelievable feeling, I'm just so happy we could get over the line.
"It's felt like a very long game but really rewarding at the end of it to come away with a win and obviously so many good performances from the boys.
"To finish it off I felt a bit of a fraud to be honest because the quick boys had done the work, but it was amazing."
England captain Stokes felt "emotional" following England's hard-fought victory, and added on Sky Sports: "The amount of effort you put in, especially in the field on day five, you get that huge rush of adrenaline and excitement.
"Twenty minutes later your body starts to get stiff and you feel a bit of a comedown. That's because of the realisation of what you've managed to achieve by winning a Test match on day five.
"It's hard to explain but it's something you only really get out of sport and it's why you absolutely love playing."