Bristol City saw their chances of a battling victory snatched from under their noses by a brilliant goal from Chesterfield defender Alex Bailey two minutes from the end of a game marred by a first half red card for Jamie Smith.
The City right-back was sent off for a wild tackle on Tcham N'Toya-Zoa that sparked a 20-man brawl in front of the Chesterfield dugout.
Referee Keith Hill had to order Smith to leave the pitch, but City staged a stirring revival after the break.
Shane Nicholson had put the home side in front from the spot, but Scott Murray and Danny Coles had City heading for victory until Bailey struck.
But the game was a scrappy one with a swirling wind making life difficult for the players.
The first half was notable only for NIcholson's penalty after Steve Phillips had brought down Mark Stallard, and for the dismissal of Smith.
The action improved for the right reasons in the second half with Murray lifting City with a brilliant 47th minute strike. The winger cut in from the right and smashed a left- foot shot past Carl Muggleton from just inside the area.
Stallard almost restored Chesterfield's lead in the 53rd minute, but 60 seconds later Chesterfield failed to defend a corner and Coles drove the ball home from eight yards. Coles rescued City minutes later when he cleared a Stallard shot off the line, and City had to defend in numbers as Chesterfield piled on the pressure.
They appeared to have weathered the storm, but in the 88th minute Bailey produced a cracking finish from 30 yards for his first senior goal.