Veteran striker James Hayter confidently gave the Glovers the lead after 18 minutes. Having been superbly put in behind the visiting defence by Gozie Ugwu’s though ball, the club’s top scorer slid home his fifth goal of the season past goalkeeper Tommy Lee.
Chesterfield could have levelled immediately but Artur Krysiak’s athletic save thwarted Drew Talbot’s goal-bound header.
Krysiak was called into action again from Byron Harrison’s flicked effort before Jimmy Ryan’s effort from long distance clipped the Glovers’ crossbar.
Sam Foley put the hosts 2-0 up in the 57th minute when Ugwu and Stephen Kingsley combined to send the midfielder racing through on goal to poke home inside the far post.
The two-goal cushion did not last long though as Chesterfield hit back after 59 minutes when Sam Hird drifted into the area to head home completely unmarked from a corner.
The Spireites were level just six minutes later when half-time substitute O’Shea picked the ball up 25 yards out and rifled an unstoppable strike past the Polish keeper.
The turnaround was complete after 68 minutes when O’Shea pounced on Kingsley’s mis-control to acrobatically finish and keep manager Paul Cook’s play-off push alive.