Andreas Weimann was the Bristol City hero as Cardiff were beaten 2-1 in an entertaining Severnside derby in the Welsh capital.
Weimann scored twice – an opportunistic effort followed by a splendid volleyed winner – as Cardiff lost for the first time in the Sky Bet Championship this season.
Daniel Bentley's own goal had put Cardiff back on terms and the visitors withstood late pressure to secure a victory that was fully merited and moves them within a point of the Bluebirds.
Cardiff dominated the opening exchanges, with Marlon Pack volleying over against his old club inside 50 seconds and fellow midfielder Joe Ralls also off target.
Bentley was brought into action for the first time when Kieffer Moore sent Ryan Giles through on goal.
Nathan Baker intervened with a superb tackle, but Bentley still had to stand firm as the ball ricocheted off Giles towards him.
Bristol took the lead after 21 minutes with a goal out of nothing as Cardiff failed to cut out Zak Vyner's ball over the top of a square defence.
Weimann had timed his run perfectly, but the chance looked lost until Aden Flint and goalkeeper Dillon Phillips dithered and the Austrian scored with a crisp finish.
Cardiff almost equalised when Moore fired a low shot past Bentley, but Andy King had retreated onto the goal-line and superbly flicked the ball off the goal-line.
Bristol were looking more comfortable as half-time approached and the home fans were becoming increasingly concerned.
But Bentley was brought into action twice in the final moments, first denying Joel Bagan a maiden senior goal and then holding Leandro Bacuna's volley at the near post.
It had been a controlled first-half performance from the visitors, but Bristol boss Nigel Pearson probably wanted his side to show greater intent in the final third.
They did so in the early moments of the second half as Han-Noah Massengo curled wide and Chris Martin was also just off-target after meeting Matty James' corner.
Bristol paid for their profligacy after Pack's shot was deflected inches wide.
The next Cardiff attack saw Pack release Moore and his attempt squeezed through the clutches of Bentley.
Baker was on the line but his attempted clearance struck the grounded Bentley for an unfortunate own goal.
But Bristol did not feel sorry for themselves and Phillips reacted well to stop a stinging drive from Antoine Semenyo.
The substitute's next contribution was a cross which Weimann, who missed most of last season through injury, flashed past Phillips at the far post for a fourth goal in three games.