Goals in either half from Anthony Elding and Byron Moore booked Crewe a place in the Carling Cup third round draw.
While Brian Wilson's stunning 30-yard strike 11 minutes from time set up a tense finish, the League One side were worthy victors over Championship opposition.
High-flying Bristol City showed just one change from their weekend victory at Coventry as boss Gary Johnson showed his intentions of progressing the furthest his club have done in the competition in five years.
Former Crewe strikers Nicky Maynard and Dele Adebola looked to be a handful in the early exchanges.
Home keeper Steve Collis was tested by Adebola's near post effort and a shot on the turn from Maynard, who Crewe sold to City earlier this month for a £2.25million fee.
Crewe emerged from their shell and had their own chances with Elding flashing one over after good work between Moore and Tom Pope.
When Pope split the City defence with a diagonal ball, Elding crossed into the box and curled an effort into the far corner beyond Chris Weale for Crewe's 24th minute opener.
Winger Joel Grant should have made it 2-0 at the start of the second half but guided a shot the wrong side of the post, while Pope was inches off hitting the bottom corner when he was presented with only Weale to beat from inside the box.
Bristol's first-half domination faded and Michael McIndoe's 20 yarder which clipped the bar was really their only threat in the second half, before Crewe added a second with 14 minutes left.
Grant skipped clear of a late tackle near the right touchline and was able to release teenager Moore, who coolly tucked the ball under Weale as the keeper came off his line.