The hosts were gifted the lead after 40 seconds when Jamie Paterson seized upon a weak Marc Roberts backpass to round goalkeeper Lee Camp and slot in from a tight angle.
Yet Birmingham responded to the early setback impressively, scoring twice before half-time to assume control.
Scott Hogan converted from close range — his second goal since arriving on loan — before Andreas Weimann scored in his own net, the former Aston Villa player inadvertently converting Jude Bellingham's cross.
After Famara Diedhiou missed a glorious chance to draw the Robins level, volleying wide on the stretch, Lukas Jutkiewicz struck late to seal the three points for Pep Clotet's side.
The striker's left-footed finish in additional time clinched Birmingham a seventh success in their past nine league trips to Ashton Gate, ending Bristol City's four-game winning streak in the Championship.