Jason Roy (87) and Ben Stokes (75) gave Eoin Morgan’s men a chance to seal England’s first 5-0 series win against any opposition on home soil as they posted 302-9.
But they were well-placed to pile up an even bigger total and their faltering finish, losing four wickets for 55 in the last 10 overs, gave Pakistan a chance which they took in a well-paced chase to salvage minor consolation and lose the series 4-1.
Hasan Ali’s career-best 4-60 limited England - and then with the onus on the hosts to bowl better than they batted, Sarfraz Ahmed and Shoaib Malik’s record stand of 163 proved decisive as Pakistan at last belied their number nine world ranking.
Sarfraz (90) and Shoaib (77) set Pakistan’s new highest one-day international partnership for the fourth wicket against England.
The wicketkeeper-batsman provided the telling impetus, with his 10 fours and a six from 73 balls.
He fell short of a second century in the series, but Pakistan had enough leeway and kept their nerve for an overdue win with 10 balls to spare.
Roy’s eight fours and two sixes from 87 balls provided the foundation for Stokes and Yorkshire’s Jonny Bairstow to repeat the dose after their match-winning stand at Headingley three days ago.
They put on 55 this time, augmenting Stokes and Roy’s 72, only for England’s innings to fall away - but still scramble past 300 after they had been put in under persistent cloud cover.
The hosts lost Alex Hales, chipping a variation slower ball from Mohammad Amir (3-50) round the wicket to mid-on, and Yorkshire’s Joe Root - inside-edging Hasan on to his stumps - in the first 10 overs.
Morgan fell disappointingly too when he mis-timed a full toss straight back at Imad Wasim, the Swansea-born spinner taking a wicket with only his third delivery back in Wales.
Stokes contributed only nine singles to the 50 stand with Roy, who had a minor moment of fortune on 55 when Mohammad Rizwan was unable to hold what would have been a memorable catch diving to his right at midwicket off Shoaib.
Stokes’ scratchy start contained a let-off too, on one, when Imad spun one back through the gate as he over-balanced but Sarfraz could not gather for the stumping chance.
It took Stokes 29 balls to reach double figures and it was not until Mohammad Nawaz replaced Imad that England’s habitually big-hitting left-hander broke out of his succession of 13 singles with his first six over long-on.
Roy mishit the returning Amir to deep square-leg, short of a fourth ODI hundred and third of the summer.
Imad restricted England to little more than three an over in two impressive spells.
But it was the return of the otherwise ineffective Umar Gul that broke the fifth-wicket stand, Bairstow falling to a simple catch at backward point as he tried to glide runs to third man from a slower short ball.
Stokes gathered momentum to reach a career-best at virtually a run a ball, with five fours and three sixes, but he missed his cue to up the ante - picking out short fine-leg after moving across his stumps to Hasan.
England therefore had to bat deep - something, on this occasion, they managed only adequately.
Pakistan’s reply was initially stop-start.
Chris Woakes had Sharjeel Khan chipping a catch to mid-on - and then after a second-wicket stand of 54, Mark Wood’s extra pace interrupted progress.
Babar Azam was bowled trying to drive one slanted in from wide on the crease, and England went to DRS to prove Azhar Ali had edged a cut behind.
But then Shoaib, with the first half-century of his long career in this country, and the admirable Sarfraz took over.
Sarfraz in particular targeted England’s debutant spinner Liam Dawson, whose wicketless four-over spell cost 41 runs - impacting perhaps on his hopes of a winter tour, as well as immediate home prospects.
Dawson returned to see off each of Pakistan’s top-scorers, both holing out as they got greedy with the big hits, and then Bairstow produced a sharp piece of work to run Nawaz out with a direct hit.
But Rizwan kept Pakistan on track with a calm contribution in an unbroken stand with Imad and England will not, therefore, go through their hugely promising limited-overs summer unbeaten.