Harlequins took a big step towards the play-offs after inflicting just a fourth defeat this season on Leicester Tigers in an entertaining game.
Will Collier and Cadan Murley scored for Quins either side of Nemani Nadolo and Hanro Liebenberg's tries as the hosts led narrowly at half-time.
Jasper Wiese's try edged Tigers into a 17-15 lead shortly before the hour.
But Quins kept going and Andre Esterhuizen scored the decisive try with six minutes remaining.
The hard-fought victory moves Quins level on points with second-placed Saracens, who play Exeter on Sunday, while Leicester have a nine-point lead at the top.
Quins were ahead inside four minutes when Alex Dombrandt broke through two tackles to offload to the supporting Collier, who got down well to pick the ball up and go over the whitewash.
But the lead didn't last long as Nadolo powered through a gaping hole in the Quins defence to score his ninth try of the season under the posts and George Ford levelled the scores at 7-7.
Marcus Smith saw a try ruled out for obstruction on 11 minutes but created one two minutes later, spinning a wonderful pass wide to allow Murley to drop over the line and restore the lead.
Tigers were back level with a well-worked try, started in their own half by Nadolo, who offloaded to Matias Moroni, and the Argentine centre cut inside before finding skipper Liebenberg who went over to make it 12-12 after half an hour.
A Smith penalty put the hosts in the lead at the break but Leicester gained the upper hand up front in the second period and made their increasing dominance pay shortly before the hour when substitute Wiese powered over from close range.
Smith restored the lead from the tee but a penalty given away by team-mate James Chisholm allowed Freddie Burns to make it 20-18 to the visitors with eight minutes remaining.
With time running out, Louis Lynagh's break opened up space for Smith who found Esterhuizen, and the South African wouldn't be stopped as he crashed through tacklers to dot down, with Smith adding a penalty on the whistle to seal an important victory.
Harlequins senior coach Tabai Matson:
"To be able to hang on in the fight and be in the fight was really important. You have to respect Leicester for what they do. They've won 17 games and they've set the way because they're just so consistent.
"To able to arm wrestle and not give away too many penalties and score three tries is pretty important for a number of reasons, not just the result. You know what is coming against Leicester. Stopping it is really difficult even if you know it's coming.
"The good thing for us is that we're still in the top four and that has been our goal all year. Lots of work still to do but this will make us really buoyant coming in on Monday."
Tigers head coach Steve Borthwick:
"There are lots of big games. They keep coming thick and fast but I would much rather be in this position than a lot of the other teams. I want to be at a club and a team that is involved in big games.
"I want to play as many games as possible and give the supporters something to cheer about.
"It's an incredibly exciting prospect. If you go back 18 months, could you have possibly imagined Leicester Tigers would be in this position? You will not get one word of complaint from me."
Harlequins: Jones; Lynagh, Marchant, Esterhuizen, Murley; Smith, Care; Marler, Walker, Collier; Symons, Tizard; Lewies, Wallace, Dombrandt.
Replacements: Gray, Kerrod, Louw, Hammond, Chisholm, Lawday, Gjaltema, David.
Leicester Tigers: Burns; Potter, Moroni, Scott, Nadolo; Ford, Youngs; Van Wyk, Clare, Heyes; Green, Snyman, Liebenberg, Robinson, Jansen.
Replacements: Cowan-Dickie, Genge, Cole, Wells, Wiese, Wigglesworth, Hegarty, Ashton.