Blue Square Premier strugglers Forest Green were denied a famous FA Cup third round victory as Derby fought back to win a seven-goal thriller at the New Lawn.
Rams substitute Steven Davies scored the winner from the penalty spot three minutes from time, but the Coca-Cola Championship strugglers looked to be crashing out when Rovers took a two-goal lead inside 20 minutes.
Goals from Jonathan Smith and Alex Lawless put Jim Harvey's side in command, but Rob Hulse threw the Rams a lifeline by pulling a goal back six minutes before the break and a Martin Albrechtsen header restored parity on the stroke of half-time.
Paul Stonehouse put the home side back in front against the run of play with 18 minutes remaining, but Paul Green levelled five minutes later.
And Rams caretaker manager Chris Hutchings, in charge for the first time since Paul Jewell's resignation last weekend, breathed a sigh of relief when Kris Commons was brought down by Lawless in the area with three minutes to play. Lawless was shown a straight red card for a professional foul and Davies converted from the spot.
Derby have been desperately out of sorts in recent weeks and they almost went behind in the first minute when Adriano Rigoglioso forced Roy Carroll to make a sharp save.
The visitors looked vulnerable at the back and fell behind after 13 minutes when Albrechtsen's header fell into the path of Smith, who smashed a right-foot strike past Carroll from just outside the penalty area.
And there was worst to come for Hutchings' side when Forest Green doubled their lead seven minutes later.
The Derby defence failed to deal with Simon Clist's direct ball forward and Lawless slotted a right-foot finish past Carroll to stun the visitors.
But Derby got back into the game when Commons crossed from the right and Hulse forced Terry Burton to make a save, but prodded the rebound home.
Albrechtsen headed Hutchings' side level on the stroke of half-time when he headed Commons' inviting cross home from point-blank range.
Derby almost caught the non-league side cold just after the break but Luke Varney was denied by former soldier Burton in the Forest Green goal.
Hulse spurned two opportunities to put Derby in front when he lobbed over the top of the crossbar and then headed a free-kick from the dangerous Commons over the bar when unchallenged.
And the former Sheffield United frontman missed an even better opportunity on the hour-mark when he went through on goal following a pass from the increasingly influential Commons, but shot straight at Burton and Commons put the rebound wide.
But with their first notable attack of the second half Rovers regained the lead with 18 minutes remaining.
Clist produced the assist from the left wing and Carroll failed to keep out full-back Stonehouse's shot from 20 yards out.
But Derby responded four minutes later when substitute Nacer Barazite's ball forward was flicked on by Hulse into the path of Green, who slotted the ball into the bottom corner of the net.
And the comeback was complete three minutes from time when Commons raced towards goal and was upended by Lawless, who was shown a straight red card, and the referee pointed to the penalty spot.
Davies kept his composure to ensure the Rams' name will be in the hat for the fourth round.