Huddersfield Town striker Gary Taylor-Fletcher hit a hat-trick to earn his side a place in the second round of the Carling Cup.
Taylor-Fletcher finally settled a thrilling game in the 76th minute after Chesterfield twice come from behind to level before completing his treble in stoppage time.
After a cagey opening from both sides the visitors took the lead on nine minutes when Pawel Abbott planted a header over Carl Muggleton for his fifth goal of the season.
The goal sparked Chesterfield into life and Colin Larkin lifted his shot over before loan signing Kevan Hurst tested Paul Rachubka with a low drive which the keeper did well to hold.
Just before half-time, the Spireites deservedly drew level when Derek Niven nodded home Larkin's cross for his second goal of the week, however 11 minutes after he restart Town were back in front.
Danny Schofield, who has caused the home defence problems all night, cut in from the right and crossed for Taylor-Fletcher to guide a header beyond Muggleton from six yards.
But just four minutes later Chesterfield was level again, Hurst, making his home debut, raced clear and took on Andy Holdsworth before lashing home a powerful drive from 18 yards.
Taylor-Fletcher then made it 3-2 on 76 minutes after Schofield latched on to a poor back pass and squared for the former Lincoln man to tap into a empty net.
The pair combined again in injury time as Taylor-Fletcher scrambled home Schofield's cutback from the by-line.