Two goals in the last two minutes highlighted a tremendous battle between two promotion-chasing sides.
It seemed that Tranmere would sneak the verdict and move into the play-off zone when Gary Jones put them ahead for the first time in the 89th minute from a cross by Simon Haworth.
But Cardiff, chasing the second automatic promotion spot behind runaway leaders Wigan Athletic, went straight on the attack and Robert Earnshaw completed his hat-trick with a powerful low shot from a headed pass by Peter Thorne.
Rovers stopper John Achterberg made an excellent early save to deny on loan Alan Mahon and then Iain Hume brought an excellent stop from Achterberg's opposite number Neil Alexander.
Earnshaw opened the scoring ten minutes before the break with a neat lob over Achterberg when Ian Sharps failed to cut out a through ball from Willie Boland.
Tranmere drew level two minutes after half time with a glancing header by Haworth from a Sean Connelly cross - his 16th goal of the season.
Earnshaw brought the best out of Achterberg, who produced some fine saves in the home goal, before a producing a neat finish for the second Cardiff goal from a Mahon pass on 67 minutes.
The home side refused to lie down in the face of some excellent attacking play by the Welshmen. Hume was a constant thorn in the side of Cityâ€™s defence and made it 2-2 with a super strike from a Connelly pass on 78 minutes.
Hume should have struck again four minutes later when out on his own but blazed over the bar and high into the crowd.
Earnshaw took the man-of-the-match award for his hat-trick performance. Skipper Graham Kavanagh was also excellent for Cardiff, while Connelly, Shane Nicholson and Gareth Roberts worked tirelessly for the Wirral side.