Yorkshire ended a bleak Yorkshire Bank 40 season with their ninth defeat in 12 matches - however victory by four wickets with seven balls remaining for Glamorgan at Headingley ensured the Welsh county's passage into the semi-finals of the competition.
Captained by Richard Pyrah in the absence of Andrew Gale, who was rested, Yorkshire's young side gave a good account of themselves but Glamorgan's batsmen always had a 216 target well within their sights.
They were in some trouble when openers Gareth Rees and Mark Wallace soon departed to the new-ball pairing of Iain Wardlaw and Moin Ashraf but Chris Cooke led the revival with a brisk 84 from 78 balls with six fours and two sixes before he holed out to Oliver Robinson, who took a spectacular catch on the midwicket boundary.
James Allenby, Marcus North and Murray Goodwin all made useful contributions but it was the firepower of Graham Wagg that proved decisive in the end. With 31 wanted from four overs he tore into Pyrah, lashing him for three sixes in four balls.
Ashraf claimed him as his third victim, Wagg's 31 being scored off 17 balls with a four and four sixes - but by then Glamorgan were only six short of the finishing line.
Yorkshire made a dreadful start after winning the toss but were rescued by a century partnership between Dan Hodgson and New Zealand Test batsman Kane Williamson.
Dismissed first ball on his Championship debut against Nottinghamshire at Trent Bridge last week, Williamson tuned up well for Wednesday's vital top-of-the-table clash with Durham at Scarborough with a cleanly struck 45 off 69 balls, including two fours and two sixes.
Hodgson continued to bat with great composure after his Kiwi partner had gone and looked set for his maiden White Rose century until he was caught at backward point off Wagg for a career-best 90 from 98 deliveries, striking eight fours and a six.
Yorkshire's final score of 215-5 still looked some way below par, despite late runs from Adam Lyth and Leaning, but was far more than seemed likely early on.
Debutant 18-year-old batsman Jonathan Tattersall, from Harrogate, was bowled for a duck in the first over from Michael Hogan and it became 7-2 as Andrew Salter dived full length at mid-off to run out Alex Lees with a direct hit.
There was a lengthy delay at 23-2 when a ball from Simon Jones appeared to be deflected from Hodgson's body on to his chin and he had to receive onfield treatment, the physiotherapist also having to come out later on to make further repairs.
Off-spinner Salter kept Hodgson and Jones on their guard with some clever flight until Williamson broke free by driving him smoothly over mid-off for six and in the next over from left-armer Dean Cosker he cleared the rope at long-on.
The stand just reached three figures before Williamson was well held at mid-off by Jones to bring Allenby a wicket but Hodgson continued on his way by striking Cosker for consecutive boundaries, while Lyth drove Salter for a straight six.
The final ball of Cosker's eight overs was hit high over midwicket for six by Hodgson, who was denied his century by slicing to Cosker.
However, Lyth and Leaning added a valuable 55 together before Lyth was bowled by Hogan for 44, leaving Leaning unbeaten on 24.