Jason Koumas came off the bench to fire two stunning injury-time goals to clinch three crucial points for Cardiff and deny Doncaster a draw they thoroughly deserved.
James Coppinger, with his seventh goal of the season, looked to have grabbed a valuable point to boost Rovers' survival hopes with a 78th-minute equaliser which cancelled out Chris Burke's 15th-minute opener.
And a draw would have been nothing less than the hosts deserved having dominated proceedings at the Keepmoat Stadium, only to rue a lack of killer instinct in front of goal.
But Koumas, who had only been on the pitch for three minutes, picked the perfect moment to open his account this season with a great 90th-minute free-kick.
And the on-loan Wigan winger, amid an otherwise disappointing campaign, sealed a 3-1 win with almost the last kick of the game.
Coppinger, Franck Moussa, Simon Gillett and George Friend all went close for relegation-threatened Doncaster, but the win boosted Cardiff's hopes of a top-two finish.