Harlequins held off Bath to claim a 19-13 victory and extend their Premiership winning streak to four matches at the Recreation Ground.
Alex Dombrandt and Oscar Beard scored as Quins led 12-3 at the break.
Will Butt's try brought Bath back to within two points, but Nick David stretched Quins' advantage again.
Bath had two efforts held up on the line and were then denied a last-minute score in a dramatic finale as Quins saw out the game with 13 men.
Both George Head and Jack Kenningham were sent to the sin-bin in the final minutes, but Quins held on to strengthen their hold on third place in the table.
Quins dominated the opening 40 minutes, leaving Bath - who had also won their three previous league matches - shocked, as their handling errors and penalties racked up.
Full-back David gained the visitors their first territorial advantage, racing to the Bath 22 after a kick-chase inside three minutes. From five metres out, Dombrandt found a gap as he came around the ruck to charge between two tacklers under the posts.
Beard, on his first league start, was rewarded for making the initial line break that set up Quins' second try. After 16 phases, he was picked out by Danny Care with a long ball and side-stepped over.
While Orlando Bailey had kept Bath in touch with a penalty, he missed a further two kicks at goal and the hosts' attack was largely restricted to one excellent Joe Cokanasiga break down the wing which fell short.
Yet Quins were made to pay for not making their dominance count on the scoreboard when, with the second half barely under way, Butt ran over to bring Bath within two points.
David pushed Harlequins back more than one score clear, coolly running over after swift passing from Care and Andre Esterhuizen, but Bath's excellent defence and a huge tackle from Cokanasiga denied them a fourth try and the bonus point when the pressure dialled up.
A Piers Francis penalty then cut Quins' lead to six points, leaving Bath, who have scored more points than any team in the final 15 minutes of games so far this season, hoping of going on to secure a comeback win.
They again finished the stronger side, although Tom Dunn and Ollie Lawrence were both held up on the line.
Then in a frantic final two minutes, and with Head and Kenningham both in the bin, Bath were unable to drive over from the ensuing penalties and steal a last-minute victory.
Bath head of rugby Johann van Graan told BBC Radio Bristol:
"It was a frustrating, that last few minutes we were over the try line twice and the ball could have been grounded. A game of small margins.
"I think we had opportunities to win the game and in a game of such small margins. They had their scrum try that they finished and we were over the goal line twice and couldn't see the grounding of the ball, that's the game.
"We looked like a team that haven't played together for a few weeks. Straight after half-time we came out and scored that try.
"They're a good side, they put us under set-piece pressure - that wasn't good enough from our side across the 80 minutes. We stuck in there, we had an opportunity to win with the last play of the game. This one we really wanted to win."
Bath: Gallagher; Cokanasiga, Lawrence, Redpath, Butt; Bailey, Spencer; Morozov, Dunn, Rae, Attwood, Lee-Warner, Hill, Reid, Bayliss.
Replacements: Annett, Cordwell, Jonker, Spencer, Ellis, Green, Francis, De Carpentier.
Harlequins: David; Murley, Beard, Esterhuizen, Bassett; Allan, Care; Marler, Walker, Louw, Lamb, Herbst, Kenningham, Evans, Dombrandt
Replacements: Head, Baxter, Kerrod, Hammond, White, Gjaltema, Edwards, Anyanwu.
Sin bin: Head (79 mins), Kenningham (80+1 mins)
Referee: Andrew Brace