James Grayson's late penalty helped Northampton beat Harlequins 32-31 and put Saints in with a great chance of making the Premiership play-offs.
Saints sealed a try-scoring bonus point after 35 minutes of an exhilarating first half that saw six tries shared between the two sides.
Alex Dombrandt and Cadan Murley scored early in the second period to put Quins ahead for the first time in the game.
But Grayson's 48-metre kick with four minutes left sent the home crowd wild.
Fourth-placed Saints go six points clear of fifth-placed Exeter, with Grayson's kick also delaying third-placed reigning champions Harlequins' hopes of securing a play-off place.
Gloucester could close within a point of Northampton should they claim a bonus-point win over bottom-of-the-table Bath on Saturday.
Tommy Freeman's fourth-minute opener came after some lovely passing from Saints, but the lead only lasted three minutes as Andre Esterhuizen went in under the posts after Marcus Smith created space.
But Saints went ahead again a few minutes later as, after Dombrandt fumbled from a line-out, Northampton moved the width of the field and Lewis Ludlam got on the end of a good Alex Mitchell pass.
Saints should have moved further ahead when Mitchell's superb break gave them field position but, first, Emmanuel Iyogun was held up and then the unguarded Matt Proctor slipped as he went to gather Grayson's cross-field kick.
Having lost prop Conor Carey to an early knock, his replacement Paul Hill had to come off with a head injury, meaning the game had to go to uncontested scrums as the hosts had no fit tight-heads.
George Furbank went in from close range for Saints' third try after 24 minutes, but Huw Jones pulled one back when Joe Marchant superbly tipped a kick back to the Scotland international - that he had put over a defender and almost into touch.
But again Saints replied, this time Alex Waller forcing his way over from close range after pressure on the Quins line.
But Saints' lead came at a cost - in addition to Carey and Hill, they lost number eight Juarno Augustus in the third minute and lock Alex Coles two minutes from the break as they used half of their replacements in the opening period.
Saints seemed to look jaded as the second half began and Dombrandt cut a superb line from seven metres out to get Quins within two points, before Murley went over in the left corner after some good hands for a bonus-point try that put Quins ahead.
Harlequins replacement Santiago Garcia Botta was sin-binned for a high tackle on Furbank with 21 minutes left, but the hosts could not break through with the extra man.
The tension began to increase as the clock ticked down, but when the visitors were penalised just inside their own half late on Grayson took his shot which had distance to spare as it travelled almost the entire length of the half from a central position.
There was just time for Quins' former England scrum-half Danny Care to be sin-binned in the final minute for dissent before Chris Boyd's side recorded a famous victory as his final season at Franklin's Gardens draws to a close.
Northampton director of rugby Chris Boyd:
"Because of the injuries, we weren't able to give any relief to our forwards, who were running on empty in the second half.
"It was a gutsy effort from the whole team, especially the pack to hang in there and stay connected for long enough to secure the territory to win a couple of penalties at the death.
"Since our win against Wasps, we've been playing knockout rugby each week and the group seem to be enjoying it as just one defeat could result in the season being all over.
"It's always nice to win, but more so against a good side by playing well. We have been chugging along without a really good performance, but to defeat a strong Harlequins side is particularly satisfactory."
Harlequins senior coach Tabai Matson:
"We were lucky to be only nine points down at the interval as they were a bit sharper than us, but we did well to manage both the yellow card and the passive scrums.
"However, with two minutes to go, we should be able to close out the game and sneak a valuable away victory, but if you come to the Gardens and are not at your best then you don't get the result.
"Winning wasn't to be as it was a tough penalty call by the referee, but our boys were slow into the breakdown and we will have to review that.
"The defeat means we haven't got a 'Q' next to our name for qualification for the play-offs, so we will do our best to secure that next week against Gloucester, but we'll have to improve dramatically if we are to retain our title."
Northampton: Furbank; Proctor, Dingwall, Hutchinson, Freeman; Grayson, Mitchell; Iyogun, Haywood, Carey, Coles, Ratuniyarawa, Lawes, Ludlam (capt), Augustus.
Replacements: Fish, Waller, Hill, Moon, Hinkley, James, Francis, Sleightholme.
Harlequins: Jones; Lynagh, Marchant, Esterhuizen, Murley; Smith, Care; Kerrod, Walker, Louw, Symons, Tizard; Lewies, Lawday, Dombrandt.
Replacements: Musk, Garcia Botta, Collier, Chisholm, Wallace, Gjaltema, Allan, David.
Referee: Matthew Carley.