The game was sparked into life with four goals in five frenetic first-half minutes.
York took the lead when Garry Kenneth inadvertently headed past his own goalkeeper after a teasing delivery from the left by Ashley Chambers in the 13th minute.
Just one minute later Rovers' top scorer Tom Eaves found the net with a powerful drive past Michael Ingham.
The hosts were soon back in front as Chambers planted a simple header beyond Sam Walker following a pinpoint Matty Blair delivery.
The goals kept flowing and in the 18th minute York gave themselves a two-goal cushion through Jason Walker. The frontman was teed up by Patrick McLaughlin before volleying across his namesake and into the far corner.
Chambers soon grabbed his second of the game before the break as he outpaced Danny Woodards before lifting the ball over the onrushing goalkeeper.
It was a fifth defeat in six games for the Pirates and one too many for McGhee.