The Spireites took the lead on 27 minutes when Danny Rowe blasted in a 30-yard free-kick, but the hosts equalised instantly through Kyle Wootton.
Liam Mandeville finished off a great counter just before half-time to put the Blues ahead at the break.
Blues goalkeeper James Montgomery played the last 30 minutes injured and Wootton grabbed his second before Ellis headed the winner to break Chesterfield hearts.
Here are Liam Norcliffe’s player ratings…
Blues goalkeeper James Montgomery played the last 30 minutes injured and Wootton grabbed his second before Ellis headed the winner to break Chesterfield hearts.