Jamie Taylor grabbed the winning goal eight minutes from time as Woking won at promotion-chasing York.
Craig McAllister supplied the pass for the goal as Taylor lobbed the ball home from 12 yards with his left foot.
Clayton Donaldson had come close to giving York the lead after 23 minutes, but his header was tipped round post by Woking goalkeeper Shwan Jalal.
City then had chances to equalise, but Martyn Woolford could not find the mark with a drilled left-footed shot.
A mass brawl in the closing stages saw three sent off, with York's Nathan Peat, who had been replaced and substitute James Dudgeon, an unused sub, both sent off.
Woking assistant boss Matt Crossley was also handed his marching orders following the scuffle which erupted on the touchline.
York: Evans, Lloyd, McGurk, Goodliffe, Peat (Craddock 64), Bishop, Panther, Bowey (Stamp 61), Woolford, Donaldson, Farrell.
Subs Not Used: Reid, Dudgeon, McMahon.
Woking: Jalal, Murray, Hutchinson, Ruby, Bunce, Lambu, Evans, Smith (Oyedele 89), Sole, Taylor (Sharpling 90), McAllister.
Subs Not Used: Bittner, Jackson, Ferguson.
Booked: Bunce, Evans, Murray, Jalal.
Goals: Taylor 81.
Att: 3,173.
Ref: A Haines (Yorkshire).