Rhys Priestland's late penalty saw Bath edge out Gloucester in a scrappy West Country derby, in which both sides finished the game with 14 men.
Gloucester prop Val Rapava-Ruskin was dismissed after only eight minutes for a high challenge on Josh Bayliss.
Taulupe Faletau's try put Bath ahead just before the break, before Mike Williams was sent off after 51 minutes.
Lewis Ludlow's 75th-minute try looked to have won it for the visitors but Priestland's kick snatched the victory.
Cherry and Whites prop Rapava-Ruskin received his marching orders from referee Wayne Barnes after connecting with Bayliss' head while running into contact with the Bath second row.
Bayliss was taken from the field for a head injury assessment, from which he would later return, and Gloucester were forced into a reshuffle, sending on prop Alex Seville for centre Tom Seabrook.
Despite the setback, Gloucester were enjoying plenty of possession and territory, and two quick Bath infringements near their own line allowed Billy Twelvetrees to open up a 6-0 lead.
But the first half had a sting in the tail for the visitors when Bath substitute Jonathan Joseph sent a deft pass inside to Tom de Glanville who drew the last defender and sent Wales back row Faletau over the line. Priestland added the extras to give Bath a 7-6 half-time lead.
Priestland landed a penalty to extend the advantage but Bath's momentum was checked shortly afterwards when Williams was sent off for a high tackle on full-back Kyle Moyle.
However, Bath pulled further ahead through another Priestland penalty, before Gloucester fought their way back into the game and Twelvetrees landed a penalty with nine minutes remaining to cut the lead to 13-9.
Gloucester thought they had won it with five minutes left on the clock, when winger Louis Rees-Zammit was given space to run across the field and put Chris Harris into space, with the Scot feeding Ludlow to score in the corner.
But Twelvetrees' missed conversion would prove costly as Harris gave away a 78th-minute penalty, allowing Priestland to secure back-to-back Bath wins, and leave the Cherry and Whites rooted to the bottom of the Premiership.
Bath director of rugby Stuart Hooper told BBC Radio Bristol:
"It was definitely tense. I thought it was tit-for-tat all the way through and both teams will probably look at that and say it wasn't the best game of rugby but I'm so pleased we got the points and I'm so proud of the lads.
"Tactically we weren't right and got a bit thrown because they lost a man in the forwards and took a back off. Credit to them defensively but most of the credit goes to our lads for digging-in and getting the result.
"I can see why they've given it [the red card]. It's about accumulating points but also about performances when your backs are against the wall like this."
Gloucester head coach George Skivington:
"If you get a red card after nine minutes there is a very good chance you are going to lose, but the boys fought unbelievably hard.
"I thought they were unbelievable in the first half with their fight and collectiveness. I can't not be proud of them today.
"I don't think either of the red cards were malicious, but they are the rules and you have to live by the rules."
Bath: De Glanville; Rokoduguni, Clark, Matavesi, Muir; Priestland, Spencer; Schoeman, Dunn, Judge, Bayliss, Williams, Faletau, Reid, Mercer.
Replacements: Walker, Bhatti, Thomas, Ellis, Staddon, Chudley, Schoeman, Joseph.
Gloucester: Moyle; Rees-Zammit, Harris, Seabrook, Thorley; Twelvetrees, Heinz; Rapava-Ruskin, Walker, Balmain, Slater, Craig, Reid, Ludlow (capt), Ackermann.
Replacements: Socino, Seville, Ford-Robinson, Atkins, Clarke, Varney, Barton, Trinder.
Referee: Wayne Barnes (RFU).
Yellow card: Joseph (Bath)