Terrell Forbes won a thriller for Chesterfield against Accrington with his first goal for the club.
Jack Lester's lob put the home team ahead and he then crossed for Marc Richards to head home.
Rommy Boco's header gave Stanley hope and Peter Murphy stabbed home the equaliser before Lester again struck from close range.
Boco levelled from 18 yards but Stanley had Michael Liddle sent off before Forbes smashed home Lester's cross.
VIEWS FROM THE DRESSING ROOM
Chesterfield caretaker manager Tommy Wright tells BBC Radio Sheffield:
"I thought we had four or five players not at the races tonight and Accrington must be very disappointed they were excellent.
"I thought we were excellent when we got in their half and got crosses in the box. We looked like we were going to score.
"But I think we're a very fortunate team to get three points."
Chesterfield 13 O'Donnell 04 Forbes 05 Trotman 06 Hird 16 Ridehalgh 08 Togwell 11 Westcarr (Darwikwa - 63' ) 17 Atkinson (Allott - 88' ) 25 Talbot 09 Richards 14 Lester Booked (Randall - 88' ) Substitutes 27 Wilson 12 Darwikwa 07 Allott 15 Clay 23 Randall 18 Boden 19 Hazell Accrington Stanley 25 Dunbavin 02 Murphy 03 Liddle Dismissed 05 Nsiala Booked 07 Lindfield 04 Joyce 08 Barnett (Mingoia - 55' ) 24 Molyneux (Whichelow - 55' ) 28 Schofield Booked 33 Boco 23 Amond (Sheppard - 74' ) Substitutes 22 Dawber 18 Eckersley 10 Hatfield 15 Dixon 26 Whichelow 30 Mingoia 09 Sheppard