England clinched a remarkable 74-run victory in the final session of day five in their first Test in Pakistan since 2005.
Pakistan resumed after tea in Rawalpindi requiring just 86 more runs to win with five wickets remaining, but England fought back to secure an unlikely victory as the sun began to set over a packed stadium.
Ben Stokes' bold tactics paid off as England were rewarded with a first away win in 12 Tests.
There was a lengthy rearguard effort from Pakistan for the final wicket, with all players surrounding the bat, but it was eventually broken when Jack Leach trapped Naseem Shah lbw – the first wicket to fall to spin in the final innings.
The tourists had looked to be toiling away without reward with only three seamers on a pitch where the fast-bowling option looked the most likely to provide a breakthrough, but Ollie Robinson claimed two quick wickets in his first Test in the subcontinent to change the momentum of the match.
The England swing bowler had been dropped from the squad following a disappointing winter in Australia and the West Indies and concerns over his fitness but has bounced back in his first Test overseas since.