A last minute Toby Fricker try gave Bristol their first Premiership win in five matches as they beat Gloucester to slow their charge on a top four finish.
Harry Thacker and Andy Uren tries had put Bristol 17-0 up early on.
But replies from Charlie Chapman, Louis Rees-Zammit and Chris Harris gave Gloucester a half-time lead.
After Fricker nudged Bristol ahead, Jack Singleton's try set up a nervous finale only for Fricker to score with seconds on the clock to seal the win.
Gloucester, in fifth, pick up two bonus points to move level on points with fourth-placed Exeter. Both sides have three games remaining, although Gloucester still have to play Harlequins and Saracens.
Bristol last won in the league on 25 February, but got off to a rapid start at Ashton Gate. Thacker scored first, beating Gloucester at their own game by touching down from a driving maul.
Steven Luatua then broke down the right wing and set up Uren for a second try inside 11 minutes, before a Callum Sheedy penalty pushed them further ahead.
The Bears were totally dominating the tempo and territory but Wales winger Rees-Zammit showed all of his quality, breaking down the right flank with the Cherry and Whites' first real attack and passing inside for Chapman to score.
The momentum shifted Gloucester's way and their patience was rewarded when a gap opened in the Bristol defence, Hastings passed inside to Rees-Zammit and he darted through.
Harris nudged them into the lead with his fifth league try of the season, but there was little between the two as Bristol saw a second Thacker try ruled out for a knock-on before the break.
Bristol, who are likely to finish 10th, may have endured an inconsistent season but they stemmed Gloucester's tide well. However, they lacked a cutting edge and for all their possession put nothing on the scoreboard.
Ill-discipline cost both sides with Gloucester's Freddie Clarke sent to the bin with 13 minutes to go for a deliberate knock-on, from which Fricker raced through under the posts.
Bristol's Sam Bedlow was then sent off for a high tackle on Hastings, and Singleton surged over from close range.
But Fricker had the last word for Bristol, scoring in the corner for his second of the night to snatch the win.
Bristol director of rugby Pat Lam told BBC Radio Bristol:
"A lot of pride for that performance, only seven days ago it was probably a very disappointing, frustrating time in that changing room and afterwards it was a tough week and I knew everyone was feeling through it.
"Monday morning I had all the staff and players everyone come in and asked them all to write down what the rest of the season were, what we were playing for.
"Fans were there, it was about playing for each other, playing for the guys that are leaving, playing for pride, the jersey, all great words. I put a massive circle and said well action and we're going to be tested four times for the rest of the season, it's the only place we can answer if we really mean it.
"That's four 80-minute performances and that was the first one. It's fair to say I saw a lot of fight for all those reasons. It's fair to say I'm really proud of the guys for that."
Gloucester head coach George Skivington told BBC Radio Gloucestershire:
"I don't think we were accurate enough with set pieces to be honest with you, it's obviously been a superpower for us and that area, ironically, we couldn't get going.
"That's my responsibility, I coach that and I've got to make sure that's on point so Bristol did a great job of scuppering it and we didn't have the solutions.
"I think the first 10 minutes we got outdone physically, they really brought a high level of physicality there and I think again that's unusual for us. They came out with a serious bite and before we knew it it was 17-0.
"It wasn't panic stations, I wasn't panicked, the boys weren't panicked, the messages were clear and they worked their way back to the game. Like I say, I thought they did a good job, if you get scuppered in your opportunities and you don't get the ball out and the ball gets turned over then you're going to be in trouble and it's a hard fight from there.
"A couple of minutes to go, they fought their way back into a winning position but Bristol looked back to their best today, I thought."
Bristol: Morahan; Fricker, O'Conor, Frisch, Leiua; Sheedy, Uren; Woolmore, Thacker, Afoa, Holmes, Vui, Luatua (c), Jeffries, Harding.
Replacements: Kerr, Benz-Salomon, Armstrong, Joyce, D Thomas, Randall, Bedlow, Bates.
Red card: Sam Bedlow (70)
Gloucester: Carreras; Rees-Zammit, Harris, Atkinson, Thorley; Hastings, Chapman; Rapava-Ruskin, Socino, Balmain, Clarke, Alemanno, Reid, Ludlow (c), Ackermann.
Replacements: Singleton, Elrington, Ford-Robinson, Davidson, Morgan, Meehan, Twelvetrees, Seabrook.
Sin bin: Freddie Clarke (67)
Referee: Ian Tempest