But hooker Ace Tiatia took some of the shine of the win by being sent from the field in the 32nd minute of the game.
The Samoan hooker took a wild swing at Gloucester's Terry Sigley, but the Londoners managed admirably in his absence, and won in style – claiming a bonus point thanks to replacement James Hayter's stoppage-time try.
The win lifted Quins off the foot of the Zurich Premiership table.
The home side started well with eight points in the opening 10 minutes. Ireland international Jeremy Staunton converted a penalty and that was swiftly followed by the first try of the match from full-back Tom Williams.
Two penalties from Henry Paul soon reduced the deficit and the visitors must have thought they were odds-on for a crucial win themselves when Paul slotted over his third penalty from the halfway line after Tiatia's indiscretion.
But Harlequins responded in spectacular fashion and Staunton, who had an off-day with the boot last week, slotted two penalties before the break to put the home team five points ahead.
Staunton made it a hat-trick of strikes on goal with an early kick in the second half and Quins continued to ask questions of the opposition.
They drew further ahead on the hour mark when Simon Keogh sprinted home from 30 metres after good work from Tony Diprose and Mike Worsley, who recovered possession from a ruck which had gone awry to set up the chance for the former Ireland Under-21 international.
Keogh added another touchdown only four minutes later, sprinting home from over 60 metres out after he intercepted a James Simpson-Daniel pass.
Mindful of the extra work the 14 men had to put in, head coach Mark Evans sent on a number of replacements in the final quarter and the fresh faces were able to conjure up a fourth all-important score for the home team as Hayter was taken over the line by his pack following a lineout.
With Staunton's conversion, the crowd could celebrate what could prove a turning point in their beleaguered season.
For NEC Harlequins:Tries: Williams, Hayter, Keogh 2 Cons: Staunton 3 Pens: Staunton 4
For Gloucester:Pens: Paul 3
NEC Harlequins: 15 Tom Williams, 14 Simon Keogh, 13 Gavin Duffy, 12 Mel Deane, 11 Ugo Monye, 10 Jeremy Staunton, 9 Steve So’oialo, 8 Tony Diprose, 7 André Vos (captain), 6 Nick Easter, 5 Simon Maling, 4 Jim Evans, 3 Ceri Jones,2 Ace Tiatia, 1 Mike WorsleyReplacements: 16 James Hayter, 17 Jon Dawson, 18 Simon Miall, 19 Roy Winters, 20 Luke Sherriff, 21 Henry Barratt, 22 Andy Reay
Gloucester: 15 Jon Goodridge, 14 Seti Kiole, 13 Terry Fanolua, 12 Henry Paul, 11 James Simpson-Daniel, 10 Duncan McRae, 9 Andy Gomarsall, 1 Christo Bezuidenhout, 2 James Parkes, 3 Terry Sigley, 4 Mark Cornwell, 5 Alex Brown, 6 Peter Buxton, 7 Jake Boer (c), 8 Adam Balding.Replacements: 16 Noel Curnier, 17 Nick Wood, 18 Adam Eustace, 19 Luke Narraway, 20 Alex Page, 21 Nathan Mauger, 22 Mark Foster.
Referee: Ashley RowdenTouch judges: Huw Jones Williams, Andy MelroseAssessor: Tony Trigg