Cardiff: Sarfraz Ahmed made a classy 90 as Pakistan achieved a consolation four-wicket win in the fifth and final one-day international in Cardiff on Sunday.
England, who still won the series 4-1, were on course for their first 5-0 home ODI sweep when Pakistan, chasing 303 for victory, slumped to 77 for three after fast bowler Mark Wood took two wickets in three balls.
But Shoaib Malik (77) and Ahmed turned the tide during their stand of 163 -- a new fourth-wicket record for either side in an England-Pakistan ODI, surpassing the 122 put on by Pakistan's Ramiz Raja and Salim Malik at Nagpur in 1989.
Both batsmen eventually holed out to debutant spinner Liam Dawson, but the Hampshire left-armer finished with an expensive two for 70 in his eight overs in the Welsh capital.
Imad Wasim, born in the nearby south Wales city of Swansea, hit the winning runs when he struck a four off all-rounder Chris Jordan as Pakistan finished on 304 for six with 10 balls to spare.
Mohammad Rizwan was 34 not out and left-hander Wasim 16 not out, with England's attack missing the rested trio of frontline spinners Moeen Ali and Adil Rashid, as well as fast bowler Liam Plunkett.
"I'm really happy the team performed as it's been a tough series," said man-of-the-match Ahmed.
"We needed a partnership, we knew he (Dawson) was playing his first match so that's why we tried to play positively."
Pakistan captain Azhar Ali added: "We wanted to finish on a high...It was a much-needed victory and chasing 300 gave us much satisfaction."
Meanwhile England skipper Eoin Morgan did not have any qualms about the composition of his side.
"No regrets about the team -- it was an opportunity to get Liam Dawson on the international stage.
"It was important looking ahead to the winter (tours of Bangladesh and India) in case we go to three spinners that he had a game under his belt."
Hasan, Amir restrict England
Earlier, Jason Roy made 87 and Ben Stokes an ODI best 75 in England's 302 for nine.
At 244 for five off 40 overs England -- who posted a world record 444 for three in the third ODI in Nottingham -- were set for another big score.
But Pakistan pegged them back with paceman Hasan Ali taking an ODI best four for 60 and left-arm quick Mohammad Amir three for 50.
Pakistan were in trouble at 77 for three in the 14th over when Wood bowled Babar Azam (31) and had Azhar (33) caught behind on review.
But Malik twice lofted Dawson for six as Pakistan counter-attacked.
Wicket-keeper Ahmed went to fifty, off 44 balls, when he pulled Stokes for his seventh four, and Malik followed him to the landmark in 49 balls.
But Ahmed, who made Pakistan's first ODI hundred at Lord's in the second match of this series, fell just short of another century when he lofted Dawson and Alex Hales, back-pedalling at mid-on, held the catch.
England made a rapid start after Azhar won the toss.
Hales struck Amir, recalled in place of the injured Mohammad Irfan, for three successive fours in as many balls.
But Amir, switching to around the wicket, had his revenge two balls later when Hales (23) chipped a deliberately slower delivery to Malik at mid-on.
The lively Hasan then dismissed Joe Root for a mere nine when the batsman inside-edged an drive onto his stumps.
England were 92 for three after Wasim struck third ball when Morgan (10) tamely chipped a full toss straight back to the left-arm spinner.
Wasim, a rare shining light for Pakistan throughout the series, finished with fine figures of one for 33 in his maximum 10 overs.
In sight of what would have been his fourth ODI century, Roy top-edged a pull off Amir's clever slower-ball bouncer to Hasan at deep square leg.
Roy faced 89 balls, including eight fours and two sixes.
There was no century either for Stokes, who was out when he flicked Hasan to short fine-leg.
Pakistan's tour ends with a lone Twenty20 international against England at Manchester's Old Trafford on Wednesday.