A terrific second-half try from Tom Biggs set up victory for Bath in their local derby with Gloucester.
Bath were awarded a penalty try after an infringement by Charlie Sharples.
But two quick tries from Henry Trinder and Jonny May put Gloucester in front, before Kyle Eastmond's score helped the hosts to a five-point half-time lead.
Biggs scored the try of the night, while Gloucester, who had Darren Dawidiuk sent off, scored again through May but the hosts hung on for victory.
The home side were led out by their former hooker Lee Mears, who was forced to retire from rugby last month because of a heart problem.
Tom Heathcote successfully kicked his first attempt at goal, before a moment of controversy spiced the game up in the early stages.
Biggs was tackled off the ball a metre from the line by Sharples following a great break and chip ahead by Matt Banahan and, after deliberation by the TMO, the hosts were awarded a penalty try which Heathcote converted, while Sharples was sin-binned for his offence.
Freddie Burns missed a long-range kick for Gloucester, before they capitalised on Nick Abendanon's mistake to close the gap to five points.
The full-back's kick was charged down by Trinder who went over in the corner, although Burns missed the extras and a later penalty attempt.
Burns also went over in the left-hand corner but his try was ruled out by the TMO because of a forward pass earlier in the move.
Trinder then turned creator to set up May in the corner - another try which had to go to the TMO before being approved - and Burns added the conversion to put Gloucester 12-10 ahead.
Heathcote kicked Bath into a one-point lead and then added the extras when he created the play for Eastmond to power under the posts.
Burns's indifferent night continued when he missed a simple effort in front of the posts, before Rob Cook took over kicking duties and landed his first effort off the crossbar to close the gap to 20-15 at half-time.
Heathcote and Cook exchanged penalties immediately after the break, before Dawidiuk saw red for a tip tackle on Dave Attwood.
A fourth successful penalty of the night for Heathcote pushed Bath's lead to eight points, before Carl Fearns was sin-binned to reduce the hosts to 14 for 10 minutes.
Biggs scored a great individual try after good work from Eastmond and Abendanon, but Heathcote missed the conversion.
May scored his second try, converted by Cook, as Gloucester refused to lie down, before Heathcote put a penalty attempt wide as the game remained on a knife edge.
Gloucester replacement Ryan Mills dropped a penalty short as the visitors were left to rue the missed points from their penalty kickers.
Bath: Abendanon; Agulla, Banahan, Eastmond, Biggs; Heathcote, Stringer; James, Webber, Wilson, Day, Attwood, Louw, Fearns, Skirving.
Replacements: Catt for James (77), Batty for Webber (69), Spencer for Day (70). Not Used: Perenise, Gilbert, Claassens, Vesty, Koster.
Gloucester: Cook; Sharples, Trinder, Tindall, May; F. Burns, Robson; Wood, Dawidiuk, Harden, Lokotui, James, Savage, Qera, Kalamafoni.
Replacements: Mills for F. Burns (51), Murphy for Wood (56), Chistolini for Harden (19), Buxton for Savage (77). Not Used: Edmonds, Hazell, Lewis, M. Thomas.
Sent off: Dawidiuk (50).
Referee: Tim Wigglesworth (RFU).