Hartley's match-winning try came in the 70th minute
Northampton made it two wins out of two with a hard-fought victory over Harlequins at The Stoop.
Saints took a 13-point lead through a Chris Ashton try and eight points from the boot of Shane Geraghty before Nick Evans pulled three points back.
Quins took the lead after the interval with another two Evans penalties and a converted George Lowe try.
But the visitors replied with a try from skipper Dylan Hartley, converted by Geraghty, to secure the win.
The result left Quins still searching for their first win of the season while it was Saints' first Premiership win at The Stoop for six years.
The visitors were dominant up front in the first half and deservedly scored the opening try when winger Ashton raced on to a kick through from James Downey.
It was a different Quins side that emerged after the interval, with the backs producing far more urgency and two more Evans penalties brought them back in touch.
The hosts replaced their entire front row to give them parity in the scrum, largely thanks to 22-stone tight-head James Johnston, the heaviest player in the Premiership.
They then took the lead for the first time when a Danny Care break allowed Lowe to score under the posts in the 59th minute.
Quins looked the likelier winners at that stage with their backs constantly slicing through Saints' defence.
But with 10 minutes left the visitors won a line-out on the Quins' 22 and a backs move straight off the training ground put in Hartley for a try, with Geraghty converting.
With seconds remaining, Quins were certain they had snatched victory through Joe Marler but replays showed he had been held up over the line by Ben Foden.
Harlequins scrum-half Danny Care told BBC London 94.9: "The boys are gutted. It was so close."
"I'm gutted for the whole team, we've put in such hard work and have been training so hard all week. We really felt we should have won."
Northampton director of rugby Jim Mallinder told BBC Radio Northampton: "There was some fantastic last-ditch tackling and it was generally a really good defensive performance.
"We managed to get some scores on the board early on, but particularly when you come away from home you need some guts, some spirit and you need to hold on.
"We knew they'd come out firing on all cylinders, very passionate and enthusiastic, but we came out here determined not to be outdone on that front."
Bookmark with:
What are these?