Gloucester scraped home by a single point in a 24 23 win thanks to an injury-time penalty from Simon Mannix.
Early on Gloucester looked comfortable until Rob Liley pegged them back with second-half penalties and NEC Harlequins went ahead in the dying moments.
Mannix kicked Gloucester in front with a penalty and then converted when winger Tom Beim cut inside the Quins centres for an excellent try. It took a slice of fortune for NEC Harlequins to cut the deficit. With a Quins attack faltering, Nick Greenstock chipped over Gloucesters defence. Full-back Richard Tombs seemed to have it covered but a cruel bounce saw the ball fly straight into Jason Keyters arms a couple of yards out. Liley converted Keyters try to put the score at 13 points to 7.
Another midfield change of direction by Beim caught Quins out of position for Chris Catling to claim Gloucesters second try. Mannix this time pulled his conversion attempt wide.
In the second-half two penalties by Liley raised Quins hopes with Mannix getting one for Gloucester. Lileys third penalty of the half put NEC Harlequins within striking distance and even the loss of David Barnes, a replacement prop who was sin-binned for obstruction, did not trouble them.
NEC Harlequins outmanoeuvred Gloucester and a piercing move by the backs saw Daren OLeary level it with a try. When Liley converted to put Quins in front Gloucester managed to shake off their lethargy at last. In the dying seconds, after missing a drop-goal attempt, Mannix snatched victory for Gloucester with a penalty which kept the fans on the edge of their seats as it appeared to go wide but then swerved between the posts.