The 'Cherry and Whites' were made to fight all the way for their win, with Quins earning a bonus point for finishing within seven points, while neither sides came close to scoring four tries for a four-try bonus point.
England and Harlequins centre Will Greenwood, a prolific try-scorer at Test level, scored the first points of the game in the 26th minute, with fly-half Andy Dunne converting for a handy 7-0 lead, with Gloucester's respite finally coming four minutes before the break in the shape of a James Simpson-Daniel try.
Centre Henry Paul missed the conversion, but he knocked over a penalty in the 51st minute after Quins had built on their lead with a try by prop Ceri Jones, as flanker Pat Sanderson helped the front rower worm his way over the goalline.
Dunne converted again and Quins held a handy 14-5 lead – before Paul's penalty made it 14-8.
Drama was to follow as Chris Fortey (Gloucester) and Jim Evans (Harlequins) were sent off by by referee Tony Spreadbury for fighting, but it was the home side that remained calm as Paul slotted his second penalty in the aftemath of the brawl.
A break from Springbok fullback Thinus Delport then saw England internationals Simpson-Daniel and Paul move ahead before another England Test player, loosehead prop Trevor Woodman, got over for a try.
Paul converted for an 18-14 lead – putting Gloucester in the lead for the first time – and although Dunne struck a penalty some seven minutes from full-time, it was not enough as the home side had done enough for the win.
For Gloucester:Tries: Simpson-Daniel, WoodmanCon: PaulPens: Paul 2
For NEC Harlequins:Tries: Greenwood, JonesCons: Dunne 2Pen: Dunne