Birmingham 172 for 8 (Yates 65, Shaheen 4-29, Ball 3-33) beat Nottinghamshire 168 (Moores 73, Hasan 3-25, Lintott 3-27) by two wickets
The Bears, already sure of a place in the knock-out stages after five straight wins before this, found themselves reeling at seven for four as Shaheen, at 23 already regarded as among the best bowlers in the world in this format, gave away five wides with his first ball but then took wickets with his first, second, fifth and sixth legal deliveries.
Asked to bat first after struggling for runs in their last three matches, the Outlaws suffered an early blow as Alex Hales continued his own poor run by chopping on to Henry Brookes for four but Joe Clarke and Lyndon James found some late momentum in the powerplay, James clearing the Larwood and Voce Stand with an enormous six over midwicket off Brookes.
Yet from 61 for 1 after six overs they were checked again by the Bears spinners, with both Clarke (26) and Matt Montgomery bowled by Lintott in consecutive overs as the Outlaws reached halfway at 86 for 3.
Lintott, the left-arm wrist spinner, picked up his third wicket when James, in his most productive Blast innings to date, cut straight to backward point for 37, but gave Moores a life on 21 when he spilled what should have been an easy boundary catch off Olly Hannon-Dalby.
It turned out to be an expensive miss in the context of the innings as the wicket-keeper made the most of that and another slice of luck on 28 when a steepler off Glenn Maxwell dropped safe by hammering sixes off Maxwell, Lintott and Hannon-Dalby twice as 45 were added in the last six overs.
But that was against the loss of six wickets as Pakistan international Ali signed off his Bears stint by having Steven Mullaney caught on the fence, trapping Matt Carter leg before and bowling Moores with the last ball of the innings after Maxwell had removed Imad Wasim, leg before, and Afridi via a catch at long-on before Stone was run out as the last three balls of the innings all brought wickets.
Any hopes of straightforward night for the Bears seemed to be obliterated in Afridi's extraordinary first over, which began with five wides but then saw Alex Davies yorked and Chris Benjamin bowled attempting a scoop off the first two legal deliveries, followed by two singles and another two wickets off the final two balls, Dan Mousley falling victim to a stunning one-handed catch by Stone at short cover and Ed Barnard castled first ball by another stunning yorker.
More drama followed as Stone, playing in his first Blast match of the season after a long absence with a hamstring injury, had to leave the field after bowling just three balls. Yates began to assert himself with sixes off Carter and Ball but Maxwell bottom-edged into his stumps off Ball and the Bears were 60 for 5.
Thanks to Afridi's heroics, the Bears were three runs behind where they needed to be on the DLS chart when rain brought an interruption with the visitors 76 for 5 after seven, but the break, which in the end cost no overs, game the Bears time to gather their senses and at 101 for 5 after 10, with Yates having completed a 27-ball fifty that included four sixes, they were beginning to look favourites.
Bethell was needlessly run out in the 12th over, putting the outcome in the balance again with 51 needed from 50 balls, but as the requirement came down to 34 from the last five overs it was clear that the Outlaws needed to be rid of Yates if they were not to slip to defeat.
In the event, they claimed his wicket with the next ball as the left-hander sent a delivery from Ball skywards and Clarke took a fine diving catch at cover as Yates departed for 65. Ball raised home hopes again when he dismissed Ali with two overs left but Henry Brookes hit the winning boundary off Imad in the final over.