Match ends, Cardiff City 0, Bristol City 1.
Bristol City are the first visiting side to win at Cardiff City this season in the Championship thanks to Josh Brownhill.
The Robins captain's spectacular strike in the 67th minute saw Lee Johnson's team climb to sixth in the table.
They were made to work for this win, with Cardiff not giving up their unbeaten home record without a fight.
The hosts, who remain 14th in the table, hit the woodwork on three occasions.
Neil Warnock's side could count themselves unfortunate to come away with nothing.
But it was Brownhill's moment of quality which proved the difference as Bristol City's promising season continued.
Cardiff are without a win on their travels this season, but have been a formidable proposition on their own patch.
They have usually delivered results without always playing particularly well, and it was Bristol City who gained the early momentum here as Marley Watkins' shot was blocked and Callum O'Dowda lifted a shot over the bar.
Yet Cardiff grew into the contest, with Nathaniel Mendez-Laing and Leandro Bacuna firing wide of the target either side of an Omar Bogle header which was saved by Daniel Bentley.
The best moment of the first period was provided by Junior Hoilett, who unleashed a fierce 25-yard drive which had Bentley beaten, but cannoned to safety of the crossbar.
Bristol City were under pressure for a spell, with Cardiff enjoying more possession than they have in many home games this term, but the visitors showed sufficient resilience to get through to half-time unscathed.
Shorn of their two top scorers this season - the suspended Danny Ward and injured Joe Ralls - Cardiff were in need some inspiration going forward.
Bogle was getting himself into dangerous positions, the big striker heading wide and then seeing a low shot blocked by Pedro Pereira.
But it was Bacuna who almost made a difference just before the hour when his long-range drive left the visitors' bar rattling for a second time.
Cardiff were looking the team most likely to go in front, yet it was their opponents who conjured a breakthrough.
When Tommy Rowe found Brownhill 25 yards from goal, the midfielder's drive had too much pace and swerve for home keeper Neil Etheridge and flew into the net.
Bristol City could have put the game to bed very quickly as Andreas Weimann took aim from close range, but Etheridge was this time able to smother.
Cardiff searched for a response, with the impressive Ashley Williams, who was jeered all day by the home crowd thanks to his Swansea connections, making a fine block to deny Mendez-Laing.
From the resulting Marlon Pack corner, the ball looped off Aden Flint's shoulder and on to the top of the bar.
When substitute Gary Madine headed straight at Daniel Bentley late on, Bristol City could celebrate their first win at Cardiff in 17 years.
Cardiff City manager Neil Warnock told BBC Sport Wales:
"I'm disappointed we haven't got three points. That's football, that's the Championship.
"It's fine margins isn't it? Apart from the first 15 minutes I thought we did well today. I thought we were unlucky with decisions, as I always do.
"You need a bit of luck. We hit the bar three times. I can't remember them causing us too much trouble. They had some pretty patterns at times but it's a hell of a strike (to win it).
"The challenge now is to try to get an away record, that's the thing. Our home form will be okay, but away from home we have got to get three points, not play well and get one point. That's the priority now for the club and the lads."
Bristol City manager Lee Johnson said:
"It was a warrior-like performance. When you play Cardiff they cause you problems by pinning you in. They have quality but they can mix it in terms of direct play and good football.
"That was a proper away performance - people putting their bodies on the line and competing for every challenge.
"The match lack a bit of quality but the absolutely unbelievable moment of quality was Josh Brownhill's strike.
"I could see when I first took him to Barnsley on loan that he was a superstar in the making. He has to go down as one of the value signings in Bristol City's history."
- 15PackBooked at 19mins
- 17TomlinSubstituted forWhyteat 75'minutes
- 33HoilettSubstituted forPatersonat 89'minutes
- 27BogleSubstituted forMadineat 83'minutes
- 32Lopes PereiraSubstituted forMooreat 86'minutes
- 4NagyBooked at 27mins
- 25RoweBooked at 53mins
- 15WatkinsSubstituted forPalmerat 63'minutes
- 31Ríos Lozano
- Tony Harrington
- Shots on Target
Second Half ends, Cardiff City 0, Bristol City 1.
Foul by Gary Madine (Cardiff City).
Tomas Kalas (Bristol City) wins a free kick in the defensive half.
Foul by Leandro Bacuna (Cardiff City).
Kasey Palmer (Bristol City) wins a free kick in the defensive half.
Attempt saved. Gary Madine (Cardiff City) header from the right side of the six yard box is saved in the top centre of the goal. Assisted by Marlon Pack with a cross.
Substitution, Cardiff City. Callum Paterson replaces David Junior Hoilett.
Corner, Cardiff City. Conceded by Daniel Bentley.
Foul by Leandro Bacuna (Cardiff City).
Callum O'Dowda (Bristol City) wins a free kick on the left wing.
Substitution, Bristol City. Taylor Moore replaces Pedro Pereira.
Foul by Pedro Pereira (Bristol City).
Nathaniel Mendez-Laing (Cardiff City) wins a free kick in the attacking half.
Substitution, Cardiff City. Gary Madine replaces Omar Bogle.
Aden Flint (Cardiff City) hits the bar with a header from the centre of the box. Assisted by Marlon Pack with a cross following a corner.
Corner, Cardiff City. Conceded by Ashley Williams.
Attempt blocked. Nathaniel Mendez-Laing (Cardiff City) left footed shot from the left side of the box is blocked.
Foul by Andreas Weimann (Bristol City).
Curtis Nelson (Cardiff City) wins a free kick in the defensive half.