Two second-half penalty tries underpinned a Bath win that meant they finished top of Pool Four, courtesy of four-time European champions Toulouse losing 27-26 against Montpellier.
It is the first time in European Cup history that a team has lost its first two group games - Bath were beaten by Glasgow and Toulouse - and still reached the last-eight.
But they were made to sweat and toil by a resilient Glasgow outfit, who stunned Bath with an early Alex Dunbar try and a brilliant Richie Vernon touchdown, while Finn Russell kicked a conversion and penalty.
George Ford booted two penalties and a conversion for Bath, with Ollie Devoto adding a conversion, ensuring that the hosts progressed after a nerve-shredding finale.
Bath made a solitary switch from the side that stunned Toulouse in France last weekend, with skipper Stuart Hooper returning to second-row duties alongside Dominic Day.
Glasgow, meanwhile, were without several players through injury that meant a largely makeshift back-row of Leone Nakarawa, Fraser Brown and Vernon, and scrum-half Niko Matawalu - who will join Bath next season - was on the bench.
Glasgow, 37-10 conquerors of Bath three months ago, immediately had their hosts in all kinds of trouble, cutting them open in defence as Dunbar powered over for a fifth-minute try that Russell converted.
It was a wake-up call for the Aviva Premiership title contenders, but their day did not show any immediate sign of improving as England centre Kyle Eastmond limped off just six minutes into the contest and was replaced by Devoto.
Bath looked to assert dominance in the set-scrums, yet they were often frustrated by referee John Lacey's interpretation, while Glasgow continued to look much more threatening with ball in hand.
A Ford penalty opened Bath's account 12 minutes before half-time, but there was no sign of the try spree they required if the home side realistically wanted to keep their quarter-final hopes alive.
Ford kicked a second penalty as the interval approached, cutting Bath's deficit to a point, and although there were growing signs of set-piece dominance, the home side still struggled to make headway against fiercely-committed opposition.
And even when the Bath pack went in pursuit of a close-range try on the stroke of half-time, Glasgow had enough defensive presence to clear possession and troop off 7-6 ahead.
Glasgow substituted both their props at half-time, which provided graphic confirmation of the pressure they were under, but Bath gained an immediate scrum penalty, while also looking to increase the tempo.
But it was Glasgow, again confirming their threat behind the scrum, who struck next through a brilliant long-range try.
Slick handling and running put the Bath defence in all kinds of trouble, and Vernon finished off an outstanding move to touch down wide out.
Glasgow had to wait before the try was confirmed - referee Lacey checked video replays of possible foul play at a ruck by Nakarawa - but he awarded it and Bath found themselves 12-6 adrift.
The visitors' lead was short-lived, though, and Bath's forwards turned up the heat to generate a penalty try awarded after Glasgow's forwards pulled down a maul near their own line.
Glasgow skipper Al Kellock was sin-binned as a result, and Ford's conversion put Bath ahead for the first time, only for Russell to land an angled penalty and secure a 15-13 advantage for Glasgow after 56 minutes.
Bath looked to have regained the lead with 15 minutes left when full-back Anthony Watson crossed in the corner following superb approach by centre Jonathan Joseph, but Glasgow escaped after video replays showed no conclusive evidence of grounding.
Glasgow's reprieve proved short-lived, though, and Bath gained a second penalty try after exerting overwhelming scrum power. Devoto converted, with Ford off the field receiving treatment, and Bath led 20-15.
Bath's rugby league recruit Sam Burgess was introduced to the action as his team looked to push on in pursuit of two more tries, but they ended the game hanging on in defence as Glasgow pressed for another score, before Lacey's final whistle ended the drama.