Peter Horne scored a dazzling last-gasp try as Glasgow ended Northampton's Heineken Cup hopes for another season.
Two Ruaridh Jackson penalties gave the hosts the lead but a Dominic Waldouck try and a conversion and penalty from Stephen Myler put Saints 10-6 up.
Josh Strauss and George Pisi traded tries before Nikola Matawalu crossed, Scott Wight converting both home tries.
Ben Foden's unconverted late try seemed to have secured a draw but Horne's fine score gave Glasgow victory.
Who plays who in last eight?
Harlequins v Munster
Clermont v Montpellier
Toulon v Leicester
Saracens v Ulster
Northampton went into the game with hopes of a victory, preferably with a bonus point, that would have given them a shot at reaching the last eight by finishing second in the group behind winners Ulster, who rounded off the pool stage
with victory at Castres.
But despite dominating most of the first half they only managed one try in the opening 40 minutes and Glasgow were a different side after the interval.
There was also a worrying sight for Northampton - and England - as second row Courtney Lawes, who had once again been outstanding, was taken off in the second half after sustaining a blow to the head.
Two early penalties from Jackson saw the hosts get the scoreboard moving before Myler popped over a penalty for the visitors, but they really needed tries to keep their European hopes alive.
They created plenty of pressure but lacked a cutting edge, although winger Jamie Elliott went desperately close, being bundled into touch by Stuart Hogg as he went over in the corner.
“We won three games and lost three games and that isn't good enough”
Jim MallinderNorthampton boss
Saints continued to press Glasgow back and they finally opened their try account when Waldouck cut back against the grain and beat three men on his way to grounding the ball against the base of a post.
The conversion was a formality for Myler and with a 10-6 half-time lead Northampton looked set fair to ramp up the pressure in the second half.
But Glasgow came out ready to give it a lash and a see-saw second period turned into a minor classic.
Six minutes in Strauss picked up from the base of a ruck and powered over despite Dylan Hartley and Lee Dickson hanging off him, with Wight, on for the injured Jackson, converting as Glasgow went back in front.
The visitors were soon back in the lead as Samoa centre Pisi stepped inside the cover and powered over out wide but Ryan Lamb, on for Myler, could not convert.
And the tit for tat scoring continued as Fiji international Matawalu, who had moved from scrum-half to the wing, plucked the ball from Foden's hands and scorched 50 metres to score.
Wight converted and with 15 minutes remaining Glasgow led 20-15, but Northampton poured forward again and levelled when England full-back Foden crossed out wide to avenge his earlier error.
Lamb missed the conversion to leave the scores level and Northampton could not force a fourth try, which would have given them not only victory but a welcome bonus point.
Instead, and with 80 minutes up on the clock, Glasgow attacked from just outside their own 22 and Horne, on as a replacement, picked up the ball on halfway.
He beat four Saints players on a weaving run to the posts before converting his own score as the hosts secured their first Heineken Cup win of the season.
View from the dressing room
Northampton boss Jim Mallinder:
"We showed that when we want to we can get performances; the win at Ulster away - the only visiting team to win at Ravenhill this season - was magnificent, but to win these competitions you need to be more consistent.
"We won three games and lost three games and that isn't good enough.
"We came up here to try and get to the quarter-finals of the Heineken Cup. We knew it was an outside chance, we needed four tries. We were close, but we weren't close enough."
Glasgow boss Gregor Townsend:
"We've shown what we can do at times in every game.
"We went down to Northampton - who were Premiership leaders at the time - and we were 15-0 up.
"We were leading for 75 minutes over at Castres, so we've shown it, we just haven't had the 80 minutes and the winning performance until now."
May for Wilson (55), Lamb for Myler (55), Roberts for Dickson (68), A. Waller for Tonga'uiha (55), Haywood for Hartley (66), Mercey for Doran-Jones (55), Oakley for Lawes (50), Sorenson for Clark (37).
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.