It was an agonising defeat for Gloucester, who had not been behind the whole match until eight minutes from time.
Victory took Bath back to the top of the table ahead of Northampton's trip to Sale on Saturday.
Second-from-bottom Gloucester lost for the seventh straight match in all competitions, but did take two bonus points from an entertaining West Country derby.
Gloucester raced into a 21-7 lead inside 25 minutes.
Georgian-born prop Val Rapava Ruskin barged over from close range, and after Bath wing Louie Hennessey streaked in to reply, Gloucester's backs took over.
Fly-half Charlie Atkinson scored a second try and centre Seb Atkinson crossed soon afterwards.
Bath, though, hit back before half-time through forward power as hooker Dan Frost and replacement back-rower Guy Pepper were both driven over to cut the champions' deficit to 21-19 at the break.
Prop Afolabi Fasogbon forced his way over early in the second period to earn Gloucester a try bonus, by which time Bath had brought on England international forwards Ben Obano, Sam Underhill and Charlie Ewels, as well as South Africa prop Thomas du Toit.
Russell then pounced to score an opportunistic try after Gloucester repelled Bath's forwards with a powerful counter-ruck in front of their line, only to spill the ball and gift the champions an easy five points.
Incredibly, though, Russel missed the conversion, and Gloucester still led 26-24 with less than 10 minutes to play.
The game seemed to have turned on Pepper's sin-binning for a foolish and unnecessary trip on Charlie Atkinson.
But Gloucester's replacement prop Ciaran Knight received his marching orders soon afterwards, and Russell kicked Bath into the lead for the first time on the night.
He then added a second penalty, and Bath held out as Gloucester launched a last-gasp effort to snatch a winning try.
