Craig Davies opened the scoring for John Sheridan's men, but Kris Commons soon equalised.
Simon Ford restored Chesterfield's lead before Mark Allott gave them a two-goal cushion in the 34th minute.
Trialist Connor Doyle pulled a goal back for Derby a minute later and Chris Porter levelled for the Rams after the break.
John Brayford put the Championship side ahead for the first time and then Commons grabbed a second from the penalty spot.
Derek Niven gave Chesterfield hope late on, but the Rams held on for a thrilling win.