David Clarkson’s first-half brace put the home side on course but Ryan Jarvis replied with a double, the second a penalty, and the Minstermen fought to the end after having substitute Ryan Bowman sent off.
Clarkson’s first goal followed a mishit clearance from Tom Allan after three minutes and the ball fell perfectly for the Scot to volley home from inside the box.
Another error gifted Clarkson his second goal half an hour later. Goalkeeper Michael Ingham dropped a Michael Smith cross and the striker fired into the roof of the net from close range.
York reduced their arrears four minutes before the break when Lee Brown blocked a shot from Bowman and Jarvis was left with a simple tap-in.
Bowman had only been on the field for three minutes as a replacement for Wes Fletcher and two minutes later he was sent-off for a penalty area dust-up with Tom Parkes.
Jarvis netted from the spot after a foul by Mark McChrystal but O’Toole fired the winner at the far post after Alfie Santos had volleyed across goal.