Joel Bagan's 99th minute winner secured all three points for the Bluebirds in a thriller at CCS.
After coming from behind, City twice had the lead in the match but stayed resolute to claim victory deep into stoppage time.
Brian Barry-Murphy elected to make three changes to the side that beat Stevenage, with Ronan Kpakio, Issak Davies and Omari Kellyman coming into the side for Perry Ng, Chris Willock and Joel Colwill.
The visitors took the lead in the 15th minute as skipper Owen Bailey was picked out in the area by Luke Molyneux, whose effort took a touch off Ryan Wintle and into the net.
City responded sharply however as Ashford’s run down the wing opened up space to find Kpakio in the area, whose shot deflected to Alex Robertson before the visitors cleared the danger.
The hosts levelled the score after Davies beat Sean Grahan on the left wing and picked out Kellyman in the area, who took a touch and struck beyond Thimothee Lo-Tutala in goal.
City took the lead for the first time in the match later via Cian Ashford, who picked up the ball just inside the Doncaster half and drove at the defence, holding off two defenders and coolly slotting home.
The visitors equalised shortly before half-time however, as Charlie Crew found Brandon Hanlan in behind the City defence, who converted into the far corner to make it 2-2.
After the break, City pressed from the ascendancy as Chris Willock, fresh off the bench beat Bailey one on one and found the head of Yousef Salech in the area, however the header sailed over the bar.
Salech wouldn’t have to wait long for another chance however, as in the next phase of play he was found by Wintle’s floated ball into the box in behind the Dons' defence and converted to once again take the lead.
The visitors did maintain their attacking intent, with City keeper Nathan Trott denying Hanlan a second after the striker leapt highest in the box but tipped his effort over the bar. However, in the 72nd minute, Harry Clifton did manage another equaliser after reaching Bailey’s header first and slotting home.
Both sides looked for a late winner, with Perry Ng's dangerous ball across the 6-yard box cleared away, while Willock’s strike deep into stoppage time drifted wide of the post.
It was to be Bagan who stepped up and become match-winner, finding the back of the net in the 99th minute from Ashford's rebounded effort. Finishing from a tight angle, the left-back sent the home crowd into raptures as he secured victory in the last possible moment.
The result ensures City extend their winning run in the league to five matches, as next up attention will be turned to a Quarter Final tie at home against Chelsea in the Carabao Cup on Tuesday, 16th December.
Cardiff City: Trott, Fish (Lawlor 45’), Bagan, Kpakio (Ng 45’), Chambers, Wintle, Robertson (Turnbull 65’), Kellyman (Robinson 76’), Davies (Willock 45’), Ashford, Salech. Subs Not Used: Turner, J. Colwill.
Doncaster Rovers: Lo-Tutala, Maxwell, Bailey, McGrath, Molyneux, Hanlan (Sharp 79”), O’Riordan (Sterry 58’), Clifton, Crew (Gibson 58’), Grehan, Close (Gotts 90’) Subs Not Used: Lawlor, Pearson, Middleton.