Richie Berrington's salvo of sixes fired Scotland to their highest one-day international total as they completed a remarkable comeback to beat Ireland in Edinburgh.
Berrington struck six maximums off 23 balls as his 56 rejuvenated the run-chase and Josh Davey sealed the win with a boundary, as Scotland reached 323-5 with all of nine balls to spare.
Ireland looked near-certain winners after Paul Stirling hit his third century in four one-day internationals to send them on their way to 320-8.
The 20-year-old took just 83 balls to reach his ton before being caught out on 113.
Scotland captain Gordon Drummond had elected to field but the hosts had no answer to Stirling and his top-order colleagues as Ireland, whose opening match against Sri Lanka had been rained off, threatened to run away with the contest in the opening half of their innings.
However, Preston Mommsen (3-26) and Davey (3-41) kept the total down and opening batsmen Kyle Coetzer (89) and Fraser Watts (54) gave Scotland a fighting chance.
The Scots seemed to have lost the initiative but Berrington and Davey (48) revived their chances before the latter sealed a memorable victory - Scotland's first in six one-day games against Ireland.
Stirling looked destined to be on the winning side after following up his knock of 109 against Pakistan last month by hitting six sixes and 10 fours.
Drummond started with a maiden over but it was one of just two for the Scots, whose bowling played into the hands of Stirling's talented array of shots.
The Middlesex batsman hit 10 from his first four balls thanks to two boundaries off Safyaan Sharif and continued to send the home fielders all over the Grange.
William Porterfield also helped set the early pace before Scotland finally found some bowling success through Davey.
Davey claimed the Ireland captain's wicket for 21 in his first over with Coetzer presented with a straightforward catch.
There was no lasting success, though. Alex Cusack came in and recorded his highest score, 71, in a one-dayer for Ireland.
Ireland were at 182 when Stirling was caught at mid-wicket by Berrington off spinner Madjid Haq and his departure failed to end the punishment, as replacement Andrew Poynter made a half-century in 33 balls with the help of two sixes and five fours.
Ireland had reached 267-3 before the Scots finally made inroads, thanks to a double from Mommsen, who bowled Poynter lbw for 51 and immediately saw off Kevin O'Brien for a duck following Haq's catch.
Cusack was caught at the boundary by Gordon Goudie off Sharif four runs later and, although Ireland easily reached the 300-mark, Scotland at least denied them a record one-day score.
Mommsen bowled out John Mooney for five before Davey claimed the scalps of Gary Wilson (22) and Trent Johnston (17) as Ireland finished nine runs short of their highest total, which came in their famous World Cup win over England in Bangalore in March - their last one-day win.
Coetzer and Fraser Watts gave the hosts the start they needed.
The pair claimed 10 in the first over and broke the 100-mark in the 15th. Watts eventually made 54 before being bowled lbw by George Dockrell. Coetzer had an escape while on 81 when Poynter dropped a catch over the boundary but he was soon bowled out by Boyd Rankin.
Scotland were four runs ahead of Ireland's total after the 30th over, on 185-2, but the run rate slowed after the loss of the openers.
However, Davey steadied the ship and Berrington then stepped the chase up a gear before being caught by Dockrell off Mooney.
The game was almost won though with Scotland needing just seven runs from three overs and Sharif came on to help Davey complete the turnaround.