There was an edge to the game from the start and it all kicked off after 14 minutes with two York forwards and Doncaster half-back Jordie Hedges being sin-binned.
Knights took the lead on 21 minutes when scrum-half Connor Robinson kicked a close-range penalty.
The Dons took the lead on 24 minutes.
They moved the ball down the right where winger Sam Doherty got away and he kicked inside and hooker Kieran Cross took advantage of York’s Andy Ellis’s failure to make it safe to touch down near enough for Harris to convert to make it 6-2.
York regained the lead with a converted try and on the balance of play were good value for their 8-6 interval lead.
The Dons started the second half strongly and Harris levelled the scores at 8-8.
Knights hit back to open up a 16-8 lead with a penalty and converted try.
Harris picked out Sanderson, who would have backed himself to score, with a long pass inside the York 20 but it was ruled forward.
Despite their earlier defensive efforts looking to be taking its toll, the Dons went close through Sanderson and full-back Richard Owen.
Debutant Cameron Scott threw them a lifeline when he caught a neat kick by stand-off Hedges - one of several to trouble York in the last quarter - and forcing his way over for a try goaled by Harris to leave just two points between the two sides.
The game remained in the balance to the final whistle but York held out to claim what could prove a vital victory come September.
Doncaster had previously won all five games in all competitions.