Two goals in the 84th and 86th minutes by City striker Robert Earnshaw kept the Bluebirds on top of Division Two after Crewe had threatened to spoil the party when Rob Hulse gave the visitors the lead three minutes after the interval.
City skipper Graham Kavanagh crashed a shot against the crossbar in the 14th minute, with Crewe keeper Clayton Ince beaten, but both sides found it difficult to prize out any clear cut openings.
Hulse struck early in the second half when he raced on to a Kenny Lunt throughball to prod past Neil Alexander in the home goal.
It looked as though that would be the only score in the game until Welsh international Earnshaw struck with those two goals in two minutes.
Dario Gradi was bitterly disappointed that his side had failed to keep Cardiff out in those closing stages.
"We stopped passing the ball in the second half and that is why we lost out. Cardiff are a top-class team, but I am sure we will also be up there near the top come the end of the season."
City marksman Earnshaw had thought that time was running out until those late strikes.
"I didn't think we were going to do it but we kept on going and it was a great relief when those goals went in.
"At 1-0 down towards the end you are usually hoping for a point so to get the win was superb."
Earnshaw, who now has ten goals for the season, never thought that he would be in double figures after just 12 games, adding: "The players around me should take most of the credit for those goals."
City boss Lennie Lawrence thought it was the best game of football he had been involved with this season: "Both sides played football, but our players and the crowd showed patience and we came through."