Bristol won their first Gallagher Premiership game of 2019 after a stirring display at Ashton Gate shaded play-off hopefuls Gloucester 28-24.
A penalty try 14 minutes from time proved the decisive moment of an intense west country derby as Gloucester's hopes of climbing above Harlequins into third place were dashed.
Flanker Dan Thomas and scrum-half Andy Uren touched down for Bristol, with Callum Sheedy kicking two penalties and Ian Madigan adding a conversion and late penalty to end a run of three Premiership defeats.
Gloucester looked to be in control when wings Tom Marshall and Ollie Thorley scored tries in quick succession during the third quarter, which followed full-back Jason Woodward's earlier touchdown, while Billy Twelvetrees slotted all three conversions and kicked a penalty.
But he missed a straightforward penalty chance 11 minutes from time when Gloucester had two players in the sin-bin before Madigan stepped up to see Bristol home.
Bristol boss Pat Lam made five changes from the side beaten by Harlequins last weekend, which included a return for fit-again wing Luke Morahan, while Gloucester showed a solitary switch after defeating Saracens seven days ago, with hooker James Hanson called up to start.
And it was the home side that struck first, going ahead after just two minutes when they capitalised superbly on a stray Gloucester clearance kick.
Bristol gathered possession inside their own half, and they immediately went for broke as Steven Luatua delivered a brilliant offload to wing Luke Daniels, before Luatua's fellow flanker Thomas rounded off a thrilling move.
Sheedy drifted the conversion attempt wide, but Bristol were off and running, rocking Gloucester through the sheer audacity of their initial onslaught.
Prop John Afoa and hooker Harry Thacker then linked up to cut open Gloucester's defence for a second time in the early stages, but Gloucester survived before plundering a 16th-minute try of their own.
Patient build-up work ended with Gloucester moving possession wide, and Woodward darted over to touch down against his former club, and Twelvetrees' touchline conversion put the visitors two points in front.
It was a strong response by Gloucester, especially as they saw skipper Willi Heinz go off for a head injury assessment and not return, but Bristol ended an entertaining 40 minutes on top.
Sheedy struck two penalties following Gloucester indiscipline on the edge of their 22, and an 11-7 interval advantage was deserved reward for a half they dominated in terms of territory.
Ireland international Madigan replaced Sheedy for the second period, but Bristol were immediately on the back foot as a Twelvetrees penalty cut the deficit.
Bristol, though, responded majestically as Morahan sliced through gaps in Gloucester's defence, found full-back Charles Piutau in support, and a sweeping move was rounded off by Uren.
It was another high-class try, and Madigan's successful touchline conversion opened up an eight-point gap, leaving Gloucester with plenty to ponder.
But they replied by scoring two tries in three minutes, with Marshall finishing brilliantly for the first, then Thorley capitalised on hesitancy in Bristol's defence for a score that had poacher's instinct stamped all over it.
Twelvetrees converted both scores, only for Gloucester to temporarily go down a player when Woodward was sin-binned by referee Karl Dickson for a deliberate knock-on that thwarted a Gloucester attack.
And with Woodward off, Bristol regained the lead when Gloucester conceded a penalty try for collapsing a Bristol maul on their own line, which also saw lock Ed Slater sin-binned and the visitors reduced to 13 players.
Madigan then secured the points with a long-range penalty two minutes from time, sealing an outstanding victory.
ga('create', 'UA-72310761-1', 'auto', {'name': 'pacontentapi'});
ga('pacontentapi.set', 'referrer', location.origin);
ga('pacontentapi.set', 'dimension1', 'By Andrew Baldock, Press Association Sport Rugby Union Correspondent');
ga('pacontentapi.set', 'dimension2', 'd1190af0-76a3-4b49-acd2-5ccf55ab44ca');
ga('pacontentapi.set', 'dimension3', 'paservice:sport,paservice:sport:uk');
ga('pacontentapi.set', 'dimension6', 'story');
ga('pacontentapi.set', 'dimension7', 'composite');
ga('pacontentapi.set', 'dimension8', null);
ga('pacontentapi.set', 'dimension9', 'sport:rugby-union');
ga('pacontentapi.send', 'pageview', { 'location': location.href, 'page': (location.pathname + location.search + location.hash), 'title': 'Bristol edge out Gloucester to take first Premiership win of 2019'});