Joe Root (107) and Jos Buttler (103) were guiding the tournament favourites towards an imposing target of 349 after Pakistan left England, number one in the ODI rankings, needing a World Cup record chase.
The pair put on 130 for the fifth wicket but both were out shortly after reaching their hundreds and the tail had too much to do.
It was a remarkable turnaround for Pakistan, whose opening match of this World Cup had seen them slump to 105 all out in a seven-wicket defeat by the West Indies at the same ground on Friday.
That defeat was their 11th straight loss in completed ODIs, including the recent 4-0 series defeat by England.
But Pakistan, who won the 2017 Champions Trophy in England, started strongly on Monday and made 348 for eight, Mohammad Hafeez top-scoring with 84.
“I know myself and my team were very confident coming into this game,” Hafeez said.
“We know that on this track we can score 340 plus,” he added, with Pakistan having exactly made 340 against England in a Trent Bridge ODI last month only to lose by three wickets.
“It’s a good pitch but still there was something for the bowlers. We got the runs in our mind we wanted to achieve and then the bowlers did a great job.”
Asked to explain how Pakistan’s batting had improved so much since Friday’s debacle, Hafeez replied: “I can only describe that it was total self-belief.
“Yes, we played a bad game against the West Indies but we knew as a team we were capable of winning matches for Pakistan.
“We had a good meeting, gave confidence to each other and that really worked today.”
No side had previously made more, batting second, to win a World Cup match than Ireland, with 329 for seven against England at Bangalore in 2011.
England’s chase got off to a bad start when Jason Roy was lbw on the sweep to leg-spinner Shadab Khan to leave them 12 for one.
Jonny Bairstow then fell for 32 when he was caught behind off Wahab Riaz, before England captain Eoin Morgan (nine) and Ben Stokes (13) were dismissed cheaply.
But Buttler and Root hit towering sixes off Hafeez as England accelerated on a pitch where they had twice set the world record for the highest ODI total.
Root pulled Hasan Ali for four to go to 97 before his quick single off Riaz saw him to a 15th ODI century in 97 balls, with nine fours and a six.
But he fell soon afterwards, steering Shadab to Hafeez at short third man to end a stand of 130 with Buttler.
Wicketkeeper Buttler, one delivery after completing a 75-ball century, was also caught at short third man, by Riaz off Mohammad Amir.
From then on England were struggling and not even Chris Woakes’ brisk 21 could prevent a Pakistan victory cheered to the echo by their loyal fans.
Earlier, Hafeez starred in an innings where Babar Azam (63) and Pakistan captain Sarfaraz Ahmed (55) also made fifties.
Pakistan were bounced out by the West Indies and England deployed similar tactics after Morgan won the toss.
But Pakistan coped and it was off-spinner Moeen Ali who took the first three wickets.
England, who launched their World Cup campaign with a 104-run thrashing of South Africa, were surprisingly sloppy in the field, while their fast bowlers were expensive – Jofra Archer’s 10 wicketless overs cost 79 runs.
“We’ve gone from probably one of our best performances in the field at the Oval to not extremely bad, but it’s cost us probably about 15 or 20 runs in the field, which is a lot in a one-day game,” admitted Morgan.
Pakistan attacked from the start, with openers Fakhar Zaman and Imam-ul-Haq sharing a stand of 82.
Babar completed a run-a-ball fifty while Hafeez pressed on after being dropped on 14 when Roy floored a sitter at mid-off.