James Chisholm stunned the Wasps’ backline by picking up and driving over in the last minute, shortly after Wasps flanker James Haskell was shown a straight red card for a high tackle on Wales centre Jamie Roberts.
Marcus Smith, in a week that saw him sign a new contract with a 900% pay rise, came off the bench to inspire Quins to a bonus-point win thanks to tries from Ross Chisholm, James Lang, Danny Care and Elia Elia.
Wasps scored four tries of their own and pick up two bonus point, but had looked certain to win until the final moments.
Mathematically they can still qualify for the knock-out phase, but they face mission impossible against pool leaders Ulster at the Ricoh Arena next weekend to progress.
An uneventful first quarter came alive in the 17th minute when Wasps attacked from a line-out and were rewarded by crossing several phases later.
Drives from Haskell and Jake Cooper-Woolley sent Quins backwards before quick hands by Willie le Roux and Thomas Young enabled Kyle Eastmond to accelerate over the whitewash.
Wasps struck for a second time three minutes later when Care and the superb James Lang spilt the ball between them, enabling a counter-attack that saw Nizaam Carr run 60 metres to cross.
Both tries had been scored with Quins prop Lewis Boyce in the sin-bin for tackling Ashley Johnson without the ball and it was the Wasps hooker who touched down for the third.
Route one was the path over the line this time, Joe Launchbury catching the line-out ball as the prelude to a drive that ended when Johnson grounded the ball.
Quins took advantage of a broken field to begin their response, Lang punting ahead for Ross Chisholm to win the foot race and score.
The match was now finely poised and when Care set-off from a five-metre scrum, delaying his pass for Lang to skip over, the home side were over for a second.
Quins’ fightback was interrupted 14 minutes after half-time and once again a line-out proved to be their undoing.
Young carried into the heart of the defence and with gaps appearing out wide Danny Cipriani was able to send Brendan Macken through a gap to seal the bonus point.
Christian Wade performed a try-saving tackle on Tim Visser but the pressure continued to build through a succession of short-range drives that were completed when Care burrowed over.
All the momentum was with Harlequins and with replacement fly-half Marcus Smith orchestrating play brilliantly, they claimed their fourth try that started with Visser’s break inside and finished when Smith sent Elia over with a long floated pass.
And Wasps’ fate was sealed when James Chisholm drove across the line with seconds to spare.