Durham 193 for 2 (MacLeod 83, Stoneman 82*) beat Derbyshire 180 for 9 (Broom 68, Durston 44, Borthwick 3-33) by 13 runs
Both teams went into the match knowing that victory could get them into the NatWest T20 Blast quarter-finals if either Warwickshire or Yorkshire lost.
Warwickshire duly obliged, so Durham overtook them to go through in fourth place. It was due reward for amassing 193 for two, to which Derbyshire replied with 180 for 9.
The visitors were up with the rate while skipper Wes Durston was making 44 off 26 balls, but when he was third out in the eighth over they lost momentum.
It looked too tall an order by the time New Zealanders Neil Broom and Jimmy Neesham needed 99 off the last eight overs and left-hander Neesham holed out at long-on for six.
Shiv Thakor revived hopes with three sixes off the spinners in making 26 off ten balls, but once he had skied Scott Borthwick to cover it was as good as over.
Although Broom showed his class in making 68 off 43 balls, Derbyshire threw wickets away in desperation and slipped to 150 for eight before debutant wicketkeeper Alex Mellor, on loan from Warwickshire, helped to put on 26 before Broom was well caught by MacLeod at long-on in the final over.
Stoneman, who is joining Surrey at the end of the season, batted through the Durham innings for 82 off 56 balls, with eight fours and one six, while MacLeod's 83 came off 50 balls and included three sixes.
He also shared the county's previous T20 record stand of 126, set with John Hastings against Northants two years ago. Stoneman hit four fours through the off side in the first three overs, two of them in the third as Ben Cotton conceded 14.
Keaton Jennings, taking Phil Mustard's place at the top of the order, also began to find the boundary in a stand of 48. Stoneman, on 23, survived a steepler to Neesham, backtracking from mid-off, in an eventful sixth over from Thakor.
Jennings followed up by twice driving the medium pacer down the ground, but when he tried for a third wide of mid-off Chesney Hughes flung himself to his right and held a sensational catch.
Jennings' exit halted the boundaries until MacLeod hit the last two balls of the tenth over for four and six. He swept Durston's off spin behind square then lifted him over long-on to take the score to 89 after ten.
Thakor conceded only six runs in the 16th over, but then went for 17 in the 18th, leaving Neesham with the best figures of one for 25 after conceding only seven in the final over, when he also had MacLeod caught at short fine leg.
Derbyshire lost Hamish Rutherford for one in the first over, when he pulled straight to mid-wicket as Chris Rushworth picked up 2 for 14 in three overs. His other victim was Chesney Hughes, who chipped the first ball to mid-wicket when Rushworth returned for the sixth over.
At 51 for 2 after the powerplay, Derbyshire were two ahead of Durham at the same stage. But Durston departed for 44, made off 26 balls, when he tried to paddle Jennings' medium pace to fine leg and was bowled.