Mansfield Town progressed into the knockout stages of the Checkatrade Trophy after a tremendous stoppage time winner from midfielder Chris Clements.
Stags had led 2-0 after the first five minutes when CJ Hamilton and Darius Henderson netted in the first five minutes at the iPro Stadium.
But Derby fought back to level the contest, with their brace containing touches of good fortune. The first, when Jamie Hanson's free-kick took a strong deflection off the Stags' wall and the second when Andreas Weimann's pot-shot saw an almighty deflection off Stags' midfielder Oscar Gobern to spin over Scott Shearer.
The tie looked destined to head to penalties, until Clements chested the ball from 25 yards after Derby failed to clear, to curl it perfectly into the top corner to seal Stags' place in the next round.
The win became Stags' second victory in the competition after a previous win at League One Port Vale as Adam Murray's side finished second in the group stages, behind winners Doncaster Rovers.
Mansfield shook their hosts to the core as Murray's men began the game at break-neck speed.
Stags were ahead after just 90 seconds when Scott Shearer’s well-aimed long kick saw Darius Henderson rise superbly to flick it into the path of Ashley Hemmings, whose left-footed shot was too powerful for home goalkeeper Chris Weale to keep out.
The duo linked up again to deadly effect in the fifth minute.
Henderson sent it towards the visitors’ box in the direction of Hemmings, but Weale appeared to have collected it as he raced out of his goal. But after losing control of the ball in the corner of his box, Henderson was on hand to roll the ball beyond the Ram’s ‘keeper and into the net,
Derby, shell-shocked by Stags’ explosive opening, mustered up their first attempt on goal in the 11th minute. But Andrew Weimann’s 20 yard effort was aimed straight at Stags’ number one Scott Shearer.
The Rams then enjoyed a mini-spell of possession, in which they had two opportunities.
Kyron Stabana’s sweeping left cross eluded everybody inside the box and moments later captain Farrend Rawson headed narrowly wide from a corner.
Derby reduced the deficit with 24 minutes played. Stags’ conceded a free-kick 22 yards from goal and Jamie Hanson stepped up to strike it past Scott Shearer, with the aid of a wicked deflection off the Stags’ wall.
Two minutes later, the imposing Henderson turned on the right side of the Derby area to fire into the side netting after James Baxendale assisted from Rhys Bennett’s throw.
Stags’ then looked to penetrate on the left side, but Benning’s left-flank cross into the box was dealt with by Jason Shackell before Henderson could get close inside the goal area.
With 31 minutes played, Hanson got the better of Oscar Gobern inside the area, but his teasing cross towards the top corner of the Stags’ goal was defended competently in the air by Stags’ left-back Benning.
Charles Vernam’s long-range drive did little to bother Shearer as Derby sought an equaliser.
With ten minutes of the first half remaining, Stags’midfielder Jack Thomas was upended in the air, 23 yards from the Derby goal. But Chris Clements’ resulting free-kick was blocked inside the box by the head of Callum Guy, who then needed treatment during a short stoppage.
But Guy had well-recovered by the time he took a free-kick from almost 30 yards out, which sailed over the bar with only two minutes of the first half left.
Three minutes after the half-time interval, Jack Thomas made way for fellow midfielder Mitchell Rose.
Second half opportunities were scare, before Stags’ made a second change in the 59th minute as CJ Hamilton replaced James Baxendale.
And Hamilton’s first taste of the action was positive when he advanced on a promising run on the left, but his final ball into the box was found wanting,
Shirebrook-born midfielder Mason Bennett roamed forward on 65 minutes before laying it to the right for Kellan Gordon, but his cross into the box evaded everyone inside the area.
Weimann then rifled a long-distance effort over the bar for the home side.
Hamilton had a shot blocked on the edge of the Derby box as Stags’ looked to seal the tie.
Mansfield made their final change in the 73rd minute as leading marksman Matt Green came on for the impressive Darius Henderson.
Three minutes later, Benning saw his shot fly wide from 22 yards after neat build-up play on the right flank.
Clements blazed an attempt off-target a minute later amidst a spell of good pressure by the Stags.
Derby levelled in the 84 minute in incredible fashion. Bennett knocked it to the right side of the Stags' area where Weimann's hopeful attempt took an almighty deflection off Gobern to loop over Scott Shearer and underneath the angle.
In time added on, Gobern played a delicious ball to the left where Hamilton was able to pick out Matt Green inside the Derby area. But the Stags' frontman directed his header incorrectly and the ball flew back outside of the home box.
Then came the winner in the third minute of time added on.
Derby failed to pump the ball away and as Clements chested it down to control 25 yards from goal, the midfielder curled it beautifully into the top right hand corner to book Stags' passage into the next round.
DERBY: Weale, Shackell, Baird, Weimann, Hanson, Rawson (C), Bennett (Jakobsen 86), Gordon (Santos 66), Guy, Stabana, Vernam (Walker 7)
UNUSED SUBS: Ravas, Cover, Lelan, Mitchell-Lawson
STAGS: Shearer, Bennett, Howkins, Pearce, Benning, Clements, Thomas (M. Rose 48), Baxendale (Hamilton 59), Gobern, Hemmings, Henderson (Green 73)
UNUSED SUBS: Jensen, Harrison, Hoban, D. Rose
ATTENDANCE: 870 (357 Stags' fans)
REFEREE: Trevor Kettle