Harlequins regained top spot in the Aviva Premiership less than 24 hours after being deposed by reigning champions Saracens.
Their six-month tenure at the head of the table was briefly interrupted when Sarries won 45-9 at Sale on Friday night.
But, in front of a 13,882 sell-out crowd at The Stoop, three penalties from former New Zealand fly-half Nick Evans and a late try by replacement flanker Maurie Fa'asavalu secured a hard-fought victory.
Fly-half Tom Heathcote replied with two penalties for Bath. He kicked them ahead from 40 metres after four minutes but Evans equalised four minutes later.
Bath took the game to Quins in the first half but a try-saving tackle by Quins full-back Mike Brown, back from RBS Six Nations bench duty with England, kept them out.
After prop David Wilson picked up a loose ball at the breakdown, flanker Carl Fearns looked to have put number eight Simon Taylor clear until Brown produced a textbook tackle round the former Scotland star's ankles.
Quins responded with a fast-moving counter-attack involving centre George Lowe and right wing Tom Williams before Brown was forced into touch.
A similar move, instigated by scrum-half Danny Care, ended with Williams being stopped just short after taking a pass from Brown.
But the home side were temporarily reduced to 14 men when prop Joe Marler was yellow-carded by referee Wayne Barnes for a 30th-minute high tackle on Bath left wing Tom Biggs.
Bath took the lead two minutes later when Quins were caught offside in front of their posts and Heathcote kicked the simple penalty.
Harlequins twice had the chance to level the scores but the usually reliable Evans missed two straight penalty shots, from 40 and 30 metres, in the space of three minutes late in the first half.
Bath began the second half with a flourish. Heathcote split the Quins defence with a darting run and found right wing Olly Woodburn but he was stopped in full flight by former England winger Ugo Monye's excellent tackle. Heathcote put a close-range penalty kick wide and Bath were then denied a try by the television match official.
Full-back Nick Abendanon set up the chance with a piercing run before sidefooting his kick to the corner. It found Woodburn who went over but the replay showed that he had knocked on.
Abendanon then came to Bath's rescue, bravely diving on the ball as three Quins players bore down on him but he was injured in the process and replaced by Jack Cuthbert.
Evans' day went from bad to worse when he spurned a penalty shot at goal and went for touch only to squander the attacking opportunity by kicking the ball beyond the corner flag. The Kiwi fly-half finally made amends, kicking a 61st-minute penalty from wide on the left to level the scores.
Three minutes later the Quins scrum forced another penalty as they drove Bath back and Evans kicked them ahead from 40 metres.
Bath suffered a further blow when Cuthbert was sin-binned after referee Barnes ruled that he had tackled Brown in the air as the full-back fielded a high kick but it was a desperately close call.
Quins sealed victory in the 74th minute. Brown was tackled just short but replacement scrum-half Karl Dickson delivered a short pass to send Fa'asavalu crashing over. Evans' conversion attempt rebounded from the post.
Fa'asavalu was yellow-carded two minutes later for a dangerous challenge on Heathcote but Cuthbert hit the post with the resulting penalty and then missed the chance of a losing bonus point for Bath when he was wide again with the last kick of the match.