Second-half tries from Danny Care and Ugo Monye helped Harlequins beat Bath and end a four-match losing run.
Penalties from Stephen Donald and Ollie Devoto put the visitors in front before two successful kicks from replacement Ben Botica levelled the score.
Donald then added three more points to give Bath the edge at half-time.
But Care scored the opening try after the break and a second for Quins from Monye sealed the win to damage Bath's Heineken Cup hopes.
The West Country side slipped out of the top six after Exeter beat London Irish on Saturday.
Botica made a real difference after coming on for Matt Hopper, who went off with a hand injury after just 24 minutes, scoring 13 points with his boot.
Care put the hosts in front for the first time seven minutes after the break, burrowing his way through the Bath defence after Quins' forwards had driven towards the line.
Monye then celebrated his 30th birthday by scoring the hosts' second try of the afternoon, chasing a high kick from Nick Evans and dabbing down the loose ball after Bath winger Olly Woodburn and replacement full-back Jack Cuthbert made a mess of dealing with it.
The London side kept their opponents at bay after the break, scoring 17 points without reply.
Conor O'Shea's side are now only three points behind second-placed Leicester, having played a game more.
VIEWS FROM THE DRESSING ROOM
Harlequins director of rugby Conor O'Shea:
"We've done so much right this season and met so many challenges and this was another challenge for us.
"We are looking forward to the run-in. We know we have one more game to win to be top four.
"But somebody is going to have to take this title off us because we are not giving it up."
Bath head coach Gary Gold:
"I thought the guys showed a huge amount of character throughout the whole game.
"Unfortunately we made a couple of crucial errors.
"That's how good Quins are. You make those errors and they are going to make you pay."
Harlequins: Brown; Williams, Lowe, Hopper, Smith; Evans, Care; Marler, Gray, Johnston, Kohn, Robson, Guest, Robshaw (capt), Easter.
Replacements: Botiga for Hopper (25), Monye for Smith (51), Dickson for Care (60), Lambert for Marler (52), Buchanan for Gray (58), Collier for Johnston (64), Matthews for Robson (17), Wallace for Guest (64).
Bath: Devoto; Agulla, Rokoduguni, Eastmond, Woodburn; Donald, Claassens; James, Batty, Wilson, Hooper (capt), Attwood, Louw, Gilbert, Taylor.
Replacements: Cuthbert for Devoto (60), Heathcote for Eastmond (60), Stringer for Claassens (56), Catt for James (49), Guinazu for Batty (57), Perenise for Wilson (55), Spencer for Hooper (65), Mercer for Taylor (64).
Ref: Wayne Barnes (RFU).