A penalty try gave Bath victory over rivals Gloucester, who ended the game with 11 men after a fiery encounter.
The hosts led 9-6 at the break after a half which featured two yellow cards.
Gloucester's Sila Puafisi was sent off after the break as Stuart Hooper and Henry Trinder exchanged tries.
With the Cherry and Whites down to 12, with Mike Tindall and Huia Edmonds in the sin-bin, Bath earned a converted penalty try before Tavis Knoyle saw red for punching in a mass brawl.
The result, somewhat overshadowed by two red cards and five players sent to the sin-bin, means Bath cement their position in the top four, while ninth-placed Gloucester were unable to move closer to the European qualification places.
In a relatively tame first half, England pair Billy Twelvetrees and George Ford kicked all the points, with the former giving Gloucester a slight advantage.
After Twelvetrees and Ford exchanged penalties, Horacio Agulla did cross the whitewash for the visitors, only for referee Tim Wigglesworth to disallow the try for an obstruction from Matt Banahan on Tindall.
Twelvetrees then added two more kicks and Bath were hindered further by Carl Fearns's sin-bin for hands in the ruck.
Ford was able to reduce the deficit to three points with the boot, but no sooner had Fearns returned to the field, team-mate Matt Garvey received a yellow card for a tackle on Gareth Evans, which kept the back rower off for the start of the second half.
The drama escalated after the break when replacement Puafisi pole-axed Nick Abendanon and, visibly upset by his actions, the Gloucester prop started to walk before being shown a red card.
Bath made their extra man count as a huge drive saw captain Hooper touch down, but Ford could not convert, leaving the score at 11-9 to the visitors.
The game then saw uncontested scrums as Gloucester had run out of tighthead prop options.
But Bath lost lock Dave Attwood to the sin-bin, and after Twelvetrees' fourth penalty, Trinder drifted through the defence to cross for Gloucester and make it 17-11 - although his kicker missed the extras.
Consecutive yellow cards for Tindall and Edmonds ensued as tempers began to flare, and the game took another dramatic twist when Wigglesworth awarded the penalty try in the 79th minute after Gloucester collapsed a maul.
Ford had to wait for his conversion after an unsightly mass brawl broke out between the sides, and departing Wales international Knoyle was eventually sent off for punching Leroy Houston.
Ford kept his cool to kick the extras and Bath earned their first win at Kingsholm since 2006.
Gloucester director of rugby Nigel Davies told BBC Radio Gloucestershire:
"It's hugely frustrating. We did so much good in terms of stepping up and playing the type of game that we needed to win a local derby.
"There was good intent although our accuracy let us down on occasions in the first half in particular.
"Our discipline in parts was unacceptable but then some of the interpretations were pretty unacceptable. There is some clear and obvious stuff that we can't control and the lack of consistency in officiating is not good enough.
"I think what we got at the end of the game was a bit of a farce and there is a lot of frustrations of within the players because of the inconsistency throughout the game."
Bath coach Toby Booth told BBC Radio Bristol:
"I thought it was Christmas season - it was a bit like a pantomime at times.
"We're delighted with the result and we don't want to put a damp squib on it but we put ourselves under unnecessary pressure.
"I'm not talking about the yellow cards, I'm talking about the penalty count.
"But the mark of a good side is you work through that and we got better and better."
Gloucester: M Thomas; Sharples, Trinder, May, Twelvetrees; Cowan, Wood; George, Knight, Stooke, James, Tindall, Kalamafoni, Kvesic, G Evans.
Replacements: B Morgan for G Evans (40), Puafisi for Knight (46), Edmonds for George (46), Murphy for Wood (59), Hudson for James (63), Knoyle for Cowan (66), Cook for M Thomas (66), F Burns for Trinder (72).
Sin Bin: Tindall (75), Edmonds (76).
Sent Off: Puafisi (53), Knoyle (79).
Bath: Abendanon; Rokoduguni, Banahan, Eastmond, Agulla; Ford, Young; James, Batty, Wilson, Hooper, Attwood, Garvey, Fearns, Houston, Catt.
Replacements: Stringer for Young (53), Catt for James (53), Perenise for Wilson (53), Mercer for Fearns (69), Day for Catt (69), Henson for Eastmond (73), Watson for Agulla (74).
Not Used: Dunn.
Sin Bin: Fearns (28), Garvey (40), Attwood (67).
Referee: Tim Wigglesworth (RFU).