Pakistan survived a major wobble to chase down a target of 148 and claim their first Test win over England for almost five years at the Oval.
Despite the best efforts of Graeme Swann (3-50) and James Anderson (2-29), an aggressive approach, personified by Imran Farhat (33) and Salman Butt (48), saw Pakistan reach lunch on day four well placed at 115-3.
But three wickets went down in the space of four overs after the interval, leaving Umar Akmal (16no) and Mohammad Amir (4no) to drag their side to a four-wicket success.
The tourists now trail 2-1 in the series ahead of the final Test at Lord's next week and have ended a barren run against England dating back to Lahore in December 2005.
It also banished some of the memories of their previous visit to south London four years ago, when they became the first side in Test history to forfeit a match after refusing to take the field after tea on the fourth day in protest at being accused of ball-tampering by the umpires.
The result, which ended a run of six straight Test wins for England, was set up by Pakistan's bowlers, who twice kept the home batsmen to scores of less than 250 on a blameless pitch.
England added just one to their overnight second-innings position of 221-9 before Amir had Stuart Broad (6) caught at mid-on with the fourth ball of the morning.
Broad's scalp completed career-best figures of 5-52 for left-arm seamer Amir, who - at 18 years and 130 days - is the youngest bowler to take a Test five-for on English soil.
Tasked with converting a strong position into victory, all the pressure was on Pakistan's misfiring batting line-up.
With so few runs to play with, Anderson immediately raised England's hopes by removing Hameed for a golden duck with the fifth delivery of the run chase.
Having seen his second ball carved for four by Farhat, Anderson found Hameed's outside edge and Swann, despite juggling the chance, clung on at second slip.
Butt joined Farhat and the two left-handers - both short of runs in the series - took a positive approach that soon forced England captain Andrew Strauss into a rethink.
Swann was brought into the attack in just the sixth over, although he initially failed to stem the flow of runs as Farhat bludgeoned his third ball just wide of mid-on for a fifth boundary.
But the off-spinner soon had his revenge, trapping Farhat lbw for 33 after a missed sweep to end a second-wicket stand of 52. Farhat asked for a review of umpire Tony Hill's decision, which confirmed the ball had straightened sufficiently and would have hit the stumps.
Again England failed to build on the breakthrough and instead offered plenty of width for Butt's favoured off-side strokeplay.
With the calm figure of Mohammad Yousuf content to play himself in at the other end, Pakistan's captain raced to 48 before Swann made a second intervention just before lunch.
He drew Butt forward in defence and generated enough turn to find the outside edge, which ended in the hands of Paul Collingwood at slip to reduce Pakistan to 108-3.
Yousuf and Azhar Ali survived through to lunch but, with the finishing line in sight, both departed in quick succession.
Ali was run out by some distance by a throw to the non-striker's end after a misjudged attempt at a single, the ball having ricocheted off Alastair Cook at short-leg.
Anderson then evoked memories of the 2003 World Cup when he yorked Yousuf (33) with a full outswinger, similar to the one he got the same batsman with under the Cape Town floodlights - albeit for a first-ball duck on that occasion - seven years ago.
Yousuf's exit left Pakistan still needing 17 and, with just one added to the total, they were approaching crisis point when Kamran Akmal (0) shouldered arms to Swann's off-spin and was given out lbw by umpire Hill.
The elder Akmal brother burnt up the second of his side's reviews but again Hill's judgment was upheld by the technology.
With young guns Umar Akmal and Amir together at the crease and runs few and far between since lunch, England still had a chance.
Man-of-the-match Amir (4no), however, pulled Swann for a crucial boundary to jolt the moribund run-rate back into life and Akmal showed a cool head to steer Pakistan home, prompting joyous scenes on the visitors' balcony.