Darrell Clarke's side - who host bottom club Dagenham & Redbridge on 7 May - remain one point behind third-placed Oxford United.
Billy Bodin netted either side of half-time to put Rovers in control at York.
Jermaine Easter and Lee Mansell added further goals either side of Kenny McEvoy's consolation for the hosts.
York have now lost 10 of their last 15 games, while Rovers have been beaten just once since 27 February.
Bodin put the visitors ahead with a fine finish before rounding the goalkeeper to double this tally after the break.
At that stage, Bodin's double looked like sending Rovers into third spot, with Accrington being held at Wycombe, but Stanley found a winner at Adams Park with 12 minutes remaining.
Bristol Rovers ensured the battle for automatic promotion to League One will go down to the season's final day as they eased past relegated York City.