Highlights: Scotland's historic win over England
Despite making a mammoth 371 for five, thanks mainly to Calum MacLeod's brilliant 140 not out, Scotland were in danger of defeat as England's Jonny Bairstow took advantage of a good pitch and short boundaries at the Grange to make 105.
But a middle-order collapse gave non-Test nation Scotland renewed hope.
England rallied again, thanks to a 71-run eighth-wicket partnership between Moeen Ali and Liam Plunkett.
But paceman Safyaan Sharif sealed Scotland's victory with seven balls to spare when he had No.11 Mark Wood plumb lbw to spark a pitch invasion by jubilant home fans.
Scotland's first win in international cricket over England came in their first match since they were cruelly denied a place at next year's World Cup after a poor umpiring decision and rain saw them miss out in their final qualifier against the West Indies in Harare in March.
The International Cricket Council's decision to shrink the World Cup from 14 teams to 10 had already been heavily criticised long before Scotland and their fellow associate or non-Test nations impressed with the quality of their play in Zimbabwe.
Asked if Scotland had sent a message to the ICC with this win, Sharif replied: "I'm not going to say anything -- they've seen it all today."
This was an embarrassing reverse for 2019 World Cup hosts England ahead of their upcoming five-match home ODI series against Australia and a reminder of how Eoin Morgan's side have been undone in one-off games, such as last year's Champions Trophy semi-final loss to eventual winners Pakistan in Cardiff.
"(Scotland) are a very dangerous side, I thought they played close to their best cricket today and we didn't," said Morgan
"It's not the end of the world for us, it was a really good run out and good to have a practice coming into the series against Australia," he added ahead of a five-match campaign that gets underway at The Oval on Wednesday.
Scotland's total was their highest at this level, surpassing their 341 for nine against fellow non-Test nation Canada at Christchurch four years ago.
Bairstow set a record by becoming the first England batsman to make three ODI centuries in successive innings but it was not enough to deny the Scots.
Scotland saw captain Kyle Coetzer and Matthew Cross share a century stand after Morgan won the toss.
But they lost both openers in quick succession to be 107 for two.
MacLeod, however, ensured a promising start was not wasted and together with George Munsey (55) put on 107 for the fourth wicket.
The 29-year-old former Durham batsman went to a hundred off just 70 balls, his seventh at this level and the first by any Scotland batsman against England.
Jason Roy and Bairstow launched England's reply with a century stand but Bairstow holed out when he might have won the game.
Test skipper Joe Root was carelessly run out and England then lost Morgan and Alex Hales off successive deliveries to be 245 for five.
Ali's 46 threatened to spare England's blushes only for the all-rounder to be undone by a slower delivery from left-arm spinner Mark Watt.
David Sole, the captain of the Scotland rugby union side that beat England at Edinburgh's Murrayfield in 1990 to win a Grand Slam in the old Five Nations, was among the Grange crowd to watch his son Chris, one of Scotland's new-ball bowlers.