Scotland secured the biggest win in their cricketing history with a six-run defeat of England in Edinburgh.

Callum MacLeod's brilliant 140 not out took the home side to 371-5 in glorious batting conditions.

Jonny Bairstow's 54-ball century looked to have England on course until they slipped from 220-2 to 276-7.

Liam Plunkett (47 not out) and Moeen Ali (46) kept them in it, but last man Mark Wood was lbw to Safyaan Sharif from the fifth ball of the 49th over.

It is a wonderful result for Scotland, who have been improving steadily since the 2015 World Cup and were only denied a place in the 2019 tournament when rain stopped their match against West Indies in the qualifying tournament in Zimbabwe in March.

Here, against the number one ranked side in the world, the Scots gave the sort of performance that further questions the International Cricket Council's decision to cut the World Cup to only 10 teams.

For England, so impressive in limited-overs cricket in recent years, this defeat can be mentioned in the same breath as the Twenty20 humblings by the Netherlands and World Cup losses to Ireland and Bangladesh.

They must regroup for the five-match series against Australia, which begins at The Oval on Wednesday, while Scotland move on to T20s against Pakistan on Tuesday and Wednesday.

England humbled by superb Scotland

This was a magnificent occasion at the picturesque The Grange, with a flat pitch surrounded by small boundaries and a lightning outfield.

England's attack, without the injured Ben Stokes and Chris Woakes, looked toothless, but that is to take nothing from the impressive batting of the MacLeod-led Scots.

Any suggestion England were incapable of pulling off their highest ever chase was dispelled by a Bairstow innings that silenced the partisan crowd.

But England engineered their own downfall, first after Bairstow skewed to long-off, then by gifting wickets away in the middle-order collapse of five for 56.

Still, Moeen and Plunkett remained calm in a tense atmosphere in which every dot ball was cheered.

Then came the final twist. Moeen holed out to long-on, Adil Rashid was run out coming back for a second and Wood pinned by a Sharif yorker to spark joyous scenes and a celebratory pitch invasion.

MacLeod magic propels Scotland

Calum MacLeod hit the fastest century by a Scotland batsman in ODIs

Right-hander MacLeod was released by Durham at end of the 2016 season and now plays for Kent club Bexley - last Saturday he made 78 against Lordswood in the Kent Premier League.

He arrived at number three after openers Kyle Coetzer and Matthew Cross shared 103 in 13 overs, taking advantage of some indifferent new-ball bowling

MacLeod had only 11 from the first 14 balls he faced, but built by sweeping the spin of Moeen and Rashid - he went to 50 from 36 balls with a swept six off Moeen.

The 29-year-old added 93 for the third wicket with Richie Berrington and 107 for the fourth with George Munsey. When he nudged Rashid into the leg side, he became the first Scotland batsman to make a century against England, his 70-ball ton the fastest by a Scot in ODIs.

He helped the home side take 105 from the final 10 overs, sharing 53 for the fifth wicket with debutant Dylan Budge, who contributed only 11.

By the time MacLeod was done, his 94-ball stay had yielded 16 fours and three sixes but, more importantly, had set Scotland on their way to a historic victory.

Bairstow brilliance not enough for England

Bairstow's 54-ball century is the third-fastest by an England player in ODIs

For as long as the powerful Bairstow was the crease, it seemed England would overhaul their huge target with plenty of time to spare.

Crashing the ball through the covers or heaving over the leg side, he became the first England batsman to hit three successive one-day centuries.

After he departed to the medium-pace of Berrington, the chase was being marshalled by Alex Hales and Joe Root.

But, Hales' call left Root unable to make his ground at the non-striker's end and, after that, Hales, Eoin Morgan, Sam Billings and David Willey fell to loose strokes.

England needed 96 from 81 deliveries with only three wickets in hand when Plunkett arrived to support Moeen, an equation that came down to 26 from 30 when Berrington was taken for 18 in the 45th over.

Scotland, though, held their nerve. Moeen needlessly found long-on, Michael Leask's deadly throw from the deep beat Rashid's dive and Sharif's inswinging yorker was too much for number 11 Wood.

Scotland's fans invaded the pitch

Scotland's Safyaan Sharif celebrates

England's Liam Plunkett and Mark Wood after the match

'Credit to Scotland, England were poor' - what they said

Former England batsman James Taylor on TMS: "A lot of credit has to go to how Scotland performed. They were dominant, they made partnerships, ran well and scoring 371 was a brilliant effort. Every time England got on top they let Scotland back into the game, whether it was poor run outs, poor choices."

Former Scotland pace bowler Dougie Brown on TMS: "That was a magnificent game of cricket - 6,000 very happy people probably didn't expect to go home having seen something like this. If you're England, you might rather lose this game than the first game of a series against Australia."

England captain Eoin Morgan on Sky Sports: "Scotland played probably close to their best cricket, we didn't and we were punished. It's not the end of the world for us, it was a good run-out rather than having a couple of days of practice it's better to play a highly competitive game under pressure."