Ruaridh McConnochie scored two tries for Bath as they saw off Harlequins 19-12 to claim their third Gallagher Premiership win in a row.
They were given a scare though by Quins, who had snatched the lead with a spectacular try by Marcus Smith as the home side seemed to lose their focus.
But Rhys Priestland was involved twice in a counter attack before releasing McConnochie on the left touchline. The England World Cup squad member had opened the scoring with a clever move off the top of a line-out early in the first half.
The visitors' other try had come from number eight Alex Dombrandt when he charged down a Priestland clearance.
Quins conceded an early penalty for a block off the ball by Paul Lasike and made easier by some backchat, but Priestland's effort struck the post.
Bath picked up the pace with some clever interpassing in midfield and opened the scoring after forcing a line-out inside the visitors' 22. Jack Walker looped round to take perfect off-the-top ball and McConnochie came off the left wing to take the hooker's inside pass and sidestep the last defender.
Priestland could not convert but his pack continued to pile on the pressure, with former Harlequin loosehead Lewis Boyce twice involved in one of several threatening surges.
Quins held out, however, and Bath had to be content with a 45-metre angled penalty from Priestland at the end of the first quarter.
Centre Josh Matavesi crossed the line shortly after but the Rec's celebrations were silenced by the TV match official who ruled Walker's pass was forward.
Instead it was Harlequins who scored in the 28th minute through Dombrandt after Priestland was unable to get his clearance away. Now it was Smith's turn to hit the post, leaving his side trailing 8-5 at the break.
A deliberate knock-on by replacement wing Brett Heron reduced Quins to 14 soon after the break but, Chris Robshaw's industry and example ensured Bath's catch-and-drive was nullified.
Instead Quins snatched the lead with a stunning counter-attack which saw Gabriel Ibitoye just manage to get a pass inside to Smith, who turned Homer inside out on his way to the posts, adding the conversion too for a four-point lead.
It was quickly trimmed back by a Freddie Burns penalty but the visitors still looked the more confident side.
No sooner had McConnochie won a turnover from the dangerous Ibitoye in his own 22 than the Bath wing appeared on Priestland's shoulder to grab a dramatic try. It was then Burns's turn to hit the post with the conversion but Bath had wrested back the lead.
Crucially, when Quins won a penalty at a scrum, Smith missed touch with his kick. A couple of minutes later Burns had a penalty in front of the posts and Bath led 19-12.