Chesterfield booked their place in the knockout stages of the Checkatrade Trophy with a penalty shootout win over Manchester City U21s.
A topsy turvy game ended 2-2, despite the Spireites being 1-0 up with two minutes remaiming and City going down to nine men.
Keeper Joe Anyon made a crucial stop in the shootout and City’s Tyreke Wilson missed before Sam Hird stroked home the winning spot-kick.
Jack Lester’s men secured a second round trip to Fleetwood Town next week but they did it the hard way.
Joe Rowley scored with his first touch after coming on as a 72nd minute substitute and City had Charlie Oliver sent off with a quarter of an hour on the clock.
The young visitors levelled with a wonderful Ed Francis free-kick and although Tom Dele-Bashiru limped off after all three substitutions had been made to leave City down to nine, they took the lead on 90 minutes.
A lightning quick break had Chesterfield in trouble and a Lorenzo Gonzalez through ball was finished well by Lukas Nmecha.
The League Two outfit poured forward in search of a last gasp leveller and midway through the eight minutes of time added on they got it.
A Brad Barry cross was headed into the air before Chris O’Grady thundered in a half volley to earn a draw and a chance to pick up an extra point in the shootout.
It was an edgy start to the game, both sides giving away possession needlessly and looking to force mistakes from their opponents.
The first opportunity fell to City’s Javairo Dilrosun who showed his pace, cut in from the right touchline and blasted high and wide across goal with his left foot.
Seconds later Town went on the attack and Andy Kellett saw his cross drop just over Aro Muric’s crossbar.
Manchester City settled quicker into their rhythm and after Dilrosun’s second effort cleared the bar, a quick move down the right forced a vital intervention from Laurence Maguire at the near post.
Chesterfield had the ball in the net in the 18th minute following their best early move, Jak McCourt’s back heel allowing Kellett to skip into the box, find Chris O’Grady and then slot home after the striker’s shot was blocked - but the offside flag was up.
It was the start of a decent spell from the hosts, O’Grady unlucky not to get more of a touch on Kellett’s low cross, Muric down quickly to make a save.
A goal seemed certain when a deep corner was met by Jerome Binnom-Williams but he somehow headed wide.
There was little in the game for the remainder of the first half and the opening quarter of an hour after the break, but Chesterfield were forced into a change when McCourt hobbled off, despite having been penalised for the challenge that ended his evening and saw Robbie Weir make an entrance.
It took 20 minutes before there was a chance and it fell to Town, Binnom-Williams getting in down the left, cutting inside and forcing a save from Muric down low at the near post.
The keeper was in action again a minute later, getting enough on O’Grady’s 20-yard drive to push it around the post.
City were aggrieved not to have been awarded a penalty when Town stopper Anyon appeared to take the legs of the clean-through Lukas Nmecha.
And then they fell behind, Rowley heading home a Binnom-Williams cross a minute after coming on to replace De Girolamo.
Things got even better for the home side just after the goal, Charlie Oliver flying in late on Kellett and seeing a straight red card.
Chesterfield could have made the game safe when O’Grady played in Binnom-Williams but after he had beaten the last man he saw his effort saved bravely by Muric.
They were made to pay for that mistake with two minutes left on the clock, Francis curling home a wonderful free-kick to bring the game level.
And as the game ticked over into stoppage time, City broke at speed and Nmecha tucked home Lorenzo Gonzalez’ through ball to put the nine men ahead - Tom Dele-Bashiru having limped off with all the subsitutes already on the pitch.
But the drama wasn’t over, a Brad Barry cross eventually finding its way to O’Grady who turned and hammered a half volley high into the net to keep Town in the Trophy.
The Spireites poured forward in search of a winner but were only able to muster a Reed shot that rose into the stand behind the goal before the full-time whistle brought the shootout.
Nmecha opened the scoring from the spot for City before Andy Kellett blazed over.
Louis Reed drilled home to make it 1-1 and Francis put City ahead once more.
Taylor Richards’ made it 3-1 to City and Rowley reduced the defecit with a lovely spot-kick.
Chris O’Grady sent the keeper the wrong way to level at 3-3 and Anyon then saved from Demeao Duhaney.
Wilson shot wide to give Hird the chance to win it and he did, calmly slotting home to make it 4-3 Chesterfield.
Chesterfield: Anyon, Barry, Binnom-Williams, Hird, Maguire; Reed, Kellett, McCourt (Weir 57), Dimaio (Wakefield 85), De Girolamo (Rowley 72), O’Grady. Not used: Parkin, Wiseman, Dennis, Briggs.
Man City U21s: Muric, Duhaney, Oliver, Francis, Wilson, Davenport, Smith (Richards 69), Dele-Bashiru, Dilrosun (Diallo 80), Garre (Gonzalez 63), Nmecha (c). Not used: Sokol, Latibeaudiere.
Goalscorers: Rowley 74, Francis 88, Nmecha 90
Yellows: McCourt 21, Reed 55, Barry 90; Smith 64
Reds: Oliver 75
Referee: Darren Drysdale. Assistants: Anthony Moore, Stephen Wade.
Attendance: 1,266 (40 away)