Ben Stokes's unbeaten 71 rescued England from a top-order collapse as the World Cup hosts and favourites beat Pakistan by three wickets with three balls to spare at Trent Bridge.
Friday's win in a floodlit match saw England secure the series at 3-0 up with one to play, but it was far from routine.
England were cruising to a target of 341 at 201 for one when Jason Roy's dismissal for 114 sparked a collapse that saw three wickets lost for seven runs in 10 balls.
And when Moeen Ali was out for a duck, England were 216 for five.
But Stokes steadied the ship and with No 8 Tom Curran (31) got England back on track in a stand of 61.
Curran, pushing for a place in England's final 15-man World Cup squad, had already taken four for 75 in Pakistan's 340 for seven.
"We got there in the end," man-of-the-match Roy told Sky Sports.
"I knew we had a big total on the board and I got out and I knew the job wasn't done so I was very frustrated.
"But then the boys came in and finished it off extremely well."
Pakistan captain Safraz Ahmed was once again left lamenting his side's sloppy fielding.
"It was definitely tough luck for us after we put runs on the board," he said. "But unfortunately our bowling execution was not up to the mark and we didn't field well."
Earlier, Pakistan failed to capitalise on Babar Azam's hundred.
Their innings fell away following a century stand between Babar, who made 115, and Hafeez (59).