Maxime Colin deflected Romaine Sawyers' second-half shot past replacement keeper Ivan Lucic to win a game high on chances but low on quality finishing.
Bees' top scorer Scott Hogan had three great chances to put his side ahead.
Tammy Abraham could have given City the lead, but he hit the bar early in the second half before missing a one-on-one when it was easier to score.
The win moves Brentford one place and one point above City into 14th position in the Championship.
City were indebted to goalkeeper Frank Fielding who made two great saves as Hogan twice broke through in the first period, before the former England Under-21 international was forced off with a hip injury.
Abraham also had two good chances before the break, but his best efforts came after the restart as the 13-goal Chelsea loanee opted for power and crashed a shot against the bar when a composed finish might have given the Robins the lead.
Lucic denied Hogan's third one-on-one before Abraham had one of his own, but his chipped finish over Daniel Bentley was wide of the mark.
Colin secured the win, although it is doubtful he knew much about it, as Sawyers' long range effort deflected off his legs to wrong-foot Lucic.
Bristol City head coach Lee Johnson:
"I'm very disappointed by the result but okay with the performance because on another night we would have scored three or four goals.
"The game has hinged on us not taking our chances. Tammy Abraham played well and got into some good areas, but he just couldn't finish.
"He is a young player and will come again. It's a time to put an arm around him, not take out a big stick.
"I was much more concerned with how we played at Huddersfield on Saturday. Tonight it seemed as though one of us had run over a black cat."
Brentford manager Dean Smith:
"I think the ball went in off Maxime Colin's backside. Sometimes you need a bit of luck to record victories in the Championship and he will want the goal, even though it was a fantastic strike by Romaine.
"It was a tough night for us. The game was end to end with chances for both sides.
"A draw would have been a fair result, but we managed to get over the line.
"Strangely, both team's main goalscorers couldn't finish on the night. Scott Hogan for us and Tammy Abraham for them had numerous chances, mainly due to mistakes, and couldn't capitalise."
Match ends, Bristol City 0, Brentford 1.
Second Half ends, Bristol City 0, Brentford 1.
Attempt missed. Josh McEachran (Brentford) left footed shot from more than 40 yards on the left wing misses to the right. Assisted by Daniel Bentley following a fast break.
Corner,  Bristol City. Conceded by John Egan.
Attempt blocked. Lee Tomlin (Bristol City) left footed shot from outside the box is blocked.
Offside, Bristol City. Lee Tomlin tries a through ball, but Gustav Engvall is caught offside.
Korey Smith (Bristol City) is shown the yellow card for a bad foul.
Foul by Korey Smith (Bristol City).
Romaine Sawyers (Brentford) wins a free kick in the attacking half.
Offside, Bristol City. Hördur Bjorgvin Magnusson tries a through ball, but Gustav Engvall is caught offside.
Substitution, Brentford. Sullay Kaikai replaces Lasse Vibe.
Offside, Brentford. Josh McEachran tries a through ball, but Scott Hogan is caught offside.
Attempt saved. Gustav Engvall (Bristol City) right footed shot from the centre of the box is saved in the centre of the goal. Assisted by Lee Tomlin with a through ball.
Bobby Reid (Bristol City) wins a free kick on the right wing.
Foul by Romaine Sawyers (Brentford).
Substitution, Brentford. Yoann Barbet replaces Tom Field.
Corner,  Brentford. Conceded by Aden Flint.
Attempt blocked. Romaine Sawyers (Brentford) right footed shot from outside the box is blocked. Assisted by Lasse Vibe.
Attempt blocked. Josh McEachran (Brentford) left footed shot from the centre of the box is blocked. Assisted by Lasse Vibe.
Attempt blocked. John Egan (Brentford) right footed shot from the centre of the box is blocked. Assisted by Andreas Bjelland.
Corner,  Brentford. Conceded by Ivan Lucic.
Corner,  Brentford. Conceded by Adam Matthews.
Attempt missed. Luke Freeman (Bristol City) left footed shot from outside the box is high and wide to the left. Assisted by Tammy Abraham.
Lee Tomlin (Bristol City) is shown the yellow card for a bad foul.
Foul by Lee Tomlin (Bristol City).
Scott Hogan (Brentford) wins a free kick on the left wing.
Corner,  Bristol City. Conceded by Andreas Bjelland.
Attempt blocked. Lee Tomlin (Bristol City) right footed shot from outside the box is blocked.
Lee Tomlin (Bristol City) wins a free kick in the attacking half.
Foul by Ryan Woods (Brentford).
Goal!  Bristol City 0, Brentford 1. Maxime Colin (Brentford) right footed shot from the centre of the box to the centre of the goal. Assisted by Romaine Sawyers.
Attempt blocked. Romaine Sawyers (Brentford) right footed shot from outside the box is blocked. Assisted by Scott Hogan.
Substitution, Brentford. Josh McEachran replaces Nico Yennaris.
Attempt missed. Lasse Vibe (Brentford) right footed shot from outside the box is high and wide to the right. Assisted by Ryan Woods.
Tammy Abraham (Bristol City) wins a free kick on the left wing.
Foul by John Egan (Brentford).
Attempt missed. Tammy Abraham (Bristol City) right footed shot from the centre of the box misses to the left. Assisted by Bobby Reid with a through ball following a fast break.
Substitution, Bristol City. Gustav Engvall replaces Scott Golbourne.
Substitution, Bristol City. Lee Tomlin replaces Marlon Pack.
Offside, Brentford. Romaine Sawyers tries a through ball, but Tom Field is caught offside.
Brentford won successive games for the second time in the Championship this season as they edged past Bristol City.