Chesterfield dumped Manchester City out of the Carling Cup to pile more pressure on manager Stuart Pearce.
Niven scored with a superb volley
City's Greek striker Georgios Samaras scored five minutes before the break, scrambling the ball home after Bernardo Corradi hit the post with a header.
But early in the second half Caleb Folan pulled Chesterfield level with a header after a Phil Picken free-kick.
Chesterfield won the game with a stunning piece of skill as Derek Niven crashed a volley past Nicky Weaver.
City, who are fourth from bottom in the Premiership, have now lost 13 of their last 16 games.
Pearce had fielded a strong side, but they were unable to find an equaliser, as City crashed out the competition, just as they have done in the previous two seasons to lower-league clubs Oldham and Doncaster.
Folan caused Richard Dunne no end of problems, though he should have put Chesterfield in front before Corradi's goal, only to miscue from barely 10 yards out.
Chesterfield were soon behind as Corradi rose well to reach Micah Richards' cross.
Corradi's effort bounced back off the post, but Samaras was quick to bundle home the ball.
But City had not reckoned with Folan, who punished a mistake by Weaver.
The City goalkeeper misjudged Picken's curling free-kick allowing Folan to nod into the bottom corner.
Claudio Reyna's clearing header then fell to Niven, who struck a superb right-footed volley into the top corner.
Chesterfield: Roche, Picken, Hazell, Downes, Bailey, Hall, Niven, Allott, Hurst, Folan, Shaw (Allison 78).
Subs Not Used: Jordan, Jackson, Larkin, O'Hare.
Goals: Folan 51, Niven 67.
Man City: Weaver, Richards, Dunne, Distin, Jordan (Dickov 84), Reyna (Miller 71), Barton, Hamann (Ireland 78), Sinclair, Samaras, Corradi.
Subs Not Used: Hart, Beasley.
Booked: Weaver, Dunne.
Goals: Samaras 40.
Ref: K Wright (Cambridgeshire).