Jack Clifford impressed in front of the watching Eddie Jones as Tim Swiel's boot guided Harlequins past Bath at the Stoop.
Tim Visser dotted down just moments into the game at The Stoop but, despite early domination, Quins struggled to make the pressure count.
It was a lack of clinical edge that they were left to rue at the break, as they only led by one point as Kane Palma-Newport's score clawed the visitors back, although it was not enough to prevent a second defeat of the campaign.
And while Karl Dickson and Nathan Catt exchanged tries, it was left to South African Swiel to seal the deal with just a couple of minutes remaining.
Scotland international Visser opened the scoring after just three minutes, Quins dominating a scrum and moving the ball quickly for the wing to score in the corner. But with the scoreboard kept tight, Bath fancied their way back in when Semesa Rokoduguni collected a kick deep inside his half, nearly running the length of the field to score, and Tom Homer kicked the subsequent penalty.
Harlequins dominated possession thereafter and were rewarded in the 29th minute when Bath conceded a penalty in front of the posts, which Swiel easily converted.
The South African added to his tally five minutes later after the visitors were caught offside, but Palma-Newport ensured his finished the half with a flourish, the prop bulldozing his way over and the converted score making it a one-point game in south London.
Bath were clearly galvanised by their late try in the first half and took an unexpected lead in the 44th minute when James Chisholm was caught offside, allowing Homer to kick his side into a 13-11 advantage.
But just as they began to dominate possession, Bath were caught out by a quick break on the right flank that allowed Dickson to score Quins' second try, with Swiel just tucking in the conversion.
Catt put Bath 20-18 ahead when he scored a try with 66 minutes gone after video replays confirmed the ball had grounded and Homer's conversion just deflected inside the post.
It was a lead that should have been extended when Ben Tapuai galloped through Harlequins' defence and looked set to score but the impressive Swiel tackled to keep the hosts in the game.
After conceding cheap penalties in the first half, the prospect of an unlikely victory steeled Bath's defence, which withheld wave after wave of pressure from Quins backs as both sides pushed hard in a breathless encounter.
And just when it seemed the points were lost, it was Swiel who came to the rescue for Harlequins when they won a penalty from distance, the fly-half converting with a straight kick that sailed over the posts to put them narrowly ahead on 21-20.
Going to the very last play, Quins almost threw away their advantage by missing touch, only for a turnover to see the gleeful hosts launch the ball away.