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."