Harlequins ended any qualification hopes Gloucester might have had after scrapping to a 20-14 victory in the Heineken Cup at the Stoop.
Mike Brown's late try, which saw Charlie Sharples get an unlucky bounce of the ball, compounded the Cherry and Whites to a painful defeat.
Matt Hopper's converted score to go alongside a Nick Evans penalty saw Quins lead 10-3 after 18 minutes, with Freddie Burns responding.
But Gloucester led at half-time thanks to another Burns kick and a James Simpson-Daniel try.
Evans and Burns traded penalties, but Brown's try gave the hosts the win and a great chance of qualifying for the Heineken Cup quarter-finals.
It was Gloucester who opened proceedings with a penalty from Burns, as the hosts struggled to play with the fluidity they have become so familiar with.
But they responded as Evans converted one of his own before further splendid play from the fly-half saw Hopper weave his way over the whitewash.
After 26 minutes, Burns reduced the arrears with his second three-pointer and then set up Simpson-Daniel who scampered through Hopper's weak attempt at a tackle. The visiting fly-half added the extras as they edged ahead 11-10 at the break.
Harlequins and Gloucester were playing with intent but too many mistakes meant they both struggled to break some stubborn defence.
Quins arguably looked the more potent but were far too profligate at crucial moments.
Although Evans finally kicked the hosts into the lead, after several missed attempts, Burns deservedly restored Gloucester's advantage. However, the home side continued to create chances. After Nick Wood was sin-binned, Danny Care had a try disallowed. But Gloucester finally cracked when Care's grubber kick was collected by Brown to snatch the win late on.
Tries: Hopper, Brown
Con: Evans 2
Pen: Evans 2
Pen: Burns 3
Harlequins: 15 Mike Brown, 14 Tom Williams, 13 Matt Hopper, 12 Jordan Turner-Hall, 11 Ugo Monye, 10 Nick Evans, 9 Danny Care, 8 Nick Easter, 7 Chris Robshaw, 6 Maurie Fa'asavalu, 5 Charlie Matthews, 4 Olly Kohn, 3 James Johnston, 2 Joe Gray, 1 Mark Lambert.
Replacements: 16 Chris Brooker, 17 Joe Marler, 18 Tim Fairbrother, 19 Tomas Vallejos, 20 Luke Wallace, 21 Richard Bolt, 22 Rory Clegg, 23 Tom Casson.
Gloucester: 15 Jonny May, 14 Charlie Sharples, 13 Mike Tindall, 12 Eliota Fuimaono-Sapolu, 11 James Simpson-Daniel, 10 Freddie Burns, 9 Rory Lawson, 8 Luke Narraway (capt), 7 Akapusi Qera, 6 Alasdair Strokosch, 5 Alex Brown, 4 Jim Hamilton, 3 Dario Chistolini, 2 Scott Lawson, 1 Nick Wood.
Replacements: 16 Darren Dawidiuk, 17 Dan Murphy, 18 Rupert Harden, 19 Will James, 20 Matt Cox, 21 Dave Lewis, 22 Ryan Mills, 23 Henry Trinder.
Referee: Pascal Gauzere (France)