England hooker Dylan Hartley’s 69th-minute try enabled Northampton to follow up their opening victory over Premiership champions Leicester Tigers with their first away win over Harlequins for six years
The Northampton captain took a short pass from scrum-half Lee Dickson to drive in from close range after Quins had moved ahead for the first time in the game at 16-13.
Chris Ashton, leading try-scorer in last season's Premiership, had earlier picked up where he left off as Northampton opened up a 13-0 first-half lead. The England winger outpaced the Quins defence to touch down three minutes before half-time.
Harlequins paid heavily when full-back Mike Brown threw out a wayward pass as he was tackled by England lock Courtney Lawes.
The ball bounced off Quins team-mate Jordan Turner-Hall and Northampton centre James Downey hacked the ball deep into space for the chasing Ashton to kick on again before dropping on the ball over the try-line.
Fly-half Shane Geraghty, who kicked 10 points, converted to put Northampton 13-0 ahead. Geraghty, a contender for the England number 10 shirt for the autumn internationals with first-choice Toby Flood, of Leicester, currently injured, also landed two first-half penalties from three attempts.
The win was Northampton's first over Harlequins at The Stoop since September 2004, although they did win the 2009 European Challenge Cup final there, beating French side Bourgoin 15-3.
Former New Zealand fly-half Nick Evans, who earlier in the week signed a new contract which will keep him at Harlequins unil the end of the 2012-13 season, finally put Quins on the board by landing a close-range penalty with the final kick of the first half.
Evans, who was successful in seven out of seven place kicks in the opening 29-29 draw with Wasps at Twickenham last weekend, had earlier narrowly missed from 45 metres.
Northampton showed their defensive strength midway through the first half, repelling a wave of attacks from Quins.
They stopped three drives from hard-working England number eight Nick Easter, survived a slick passing move between Brown and centre George Lowe before prop Mark Lambert was dragged down just short of the line.
Harlequins claimed a try when England scrum-half Danny Care squirmed over in the 23rd minute but referee Andrew Small consulted the television match official who, following a lengthy deliberation, ruled that the ball had not been grounded.
Six minutes later, Evans, put clear by Ugo Monye, was denied a try when the referee ruled an earlier pass by Harlequins flanker Will Skinner marginally forward.
Evans landed a second penalty two minutes into the second half to reduce the deficit to seven points.
Quins swapped their entire front row in the 45th minute, replacing Lambert, Chris Brooker and Ceri Jones with Joe Marler, Matt Cairns and James Johnston.
Evans cut the gap to just four points with his third penalty in the 50th minute and, for the second week running, Harlequins rugby director Conor O'Shea switched Easter to the second row when he introduced England Saxons number eight Tom Guest from the bench.
The swap paid almost instant dividends as, six minutes later, 26-year-old Guest breached the Northampton defence before passing to Care who sent young centre Lowe in for the try which put Quins ahead for the first time.
Evans converted for a 16-13 lead before Hartley had the final say to get Northampton back in front.
The visitors had to defend desperately in the closing minutes, however, stopping Lowe and Tom Williams inches from the line before, with six seconds remaining on the clock, the video offical ruled that Marler had been held up over the line.