Saints had shone during the first 51 minutes of the match, scoring three tries that should have given them plenty of breathing space.
But Gloucester made the most of the only morsels of possession and territory they got during the first period to dot down twice, through Harry Elrington and Tom Seabrook.
It meant Saints only had a slender 20-14 lead at the break, but they built on that with a try of the season contender, from Tom Collins.
Gloucester had barely been in the Saints half, but the home fans rallied their troops and the replacements made a real difference, with Louis Rees-Zammit scoring with his first touch.
It was a completely different game after that as the hosts won penalty after penalty, kicking to the corner and turning to their dominant mauling game.
It earned Manny Iyogun a yellow card and Gloucester a penalty try before Dan Biggar put Saints back in front.
But another huge drive provided what proved to be the winning score, for Alex Craig.
Saints had one final breakaway chance, but Gloucester scrambled to stop Courtnall Skosan, sealing a crucial win in the battle for a top-four spot.
Saints have now seemingly fallen completely out of the race, following four successive league defeats.
They had travelled to Kingsholm hoping to reignite their stuttering campaign, but Chris Boyd's side lost Teimana Harrison and Paul Hill to hamstring and neck injuries respectively.
And Saints certainly didn't get off to a good start when the game kicked off, shooting themselves in the foot in shocking fashion.
Sam Matavesi took a quick lineout five metres from his own line but the long throw only found a Gloucester body, with the ball knocked back for Elrington to score.
It was a mad moment from Saints, who tried, and failed, to catch Gloucester out, and Adam Hastings rubbed salt in the wounds with the easy conversion.
Dan Biggar had a chance to cut the gap, but his penalty attempt sailed wide, to the delight of the supporters in The Shed as they quickly got stuck into the Saints fly-half.
Biggar made amends with a successful attempt on 22 minutes as Saints dominated territory and possession, while not really being able to make their way into the Gloucester red zone.
But finally the pressure told as the forwards trucked it up and the ball eventually came out to Matt Proctor, who made the telling surge towards the home line, stretching out an arm to score.
Biggar converted and Saints had a 10-7 lead, which was no more than they merited.
Alex Mitchell then produced a brilliant 50:22, giving Saints a lineout deep in Gloucester territory, but Matavesi was having a bad day on the throwing front and the opportunity was lost.
Biggar soon added another penalty to the tally after Saints won a penalty at the scrum, and the home fans were trying to summon some sort of response from their side.
But it was Saints who were completely bossing the game, and after a couple of huge carries from Alex Coles, the away side got within range, allowing Fraser Dingwall to power over.
Biggar converted, but Gloucester produced an almost immediate response as Tom Seabrook found a gap and held onto the ball to score.
Hastings converted and the gap was just six points at the break, despite the fact Gloucester had enjoyed barely any possession or territory.
Saints started the second half as they had played most of the first: on the front foot, but it was from the back foot that they would pounce to score a quite stunning try.
The away side counter-attacked brilliantly from deep and eventually Collins beat a man to finish with aplomb.
It was an incredible effort and one added to by Biggar's conversion to make it 27-14.
Saints then had to endure a long spell of defence as Gloucester tried to respond, but the away side looked to have weathered to storm when they held up an attack and cleared.
However, Rees-Zammit came off the bench and scored with his first touch, racing in from just inside the Saints half.
Hastings converted to cut the gap to six points and it was very much game on with more than 15 minutes still to play.
Gloucester were ramping up the heat and their fans were lifting the noise levels.
And after another penalty was conceded by Saints, the hosts kicked to the corner, producing an inexorable lineout drive, that earned a penalty try and a yellow card for Iyogun.
Gloucester had bagged the bonus point and they were now looking to put the game to bed against a stunned 14 Saintsmen.
But a big carry from Brandon Nansen earned Saints a penalty inside the Gloucester half, and Biggar did brilliantly to land it in increasingly windy conditions.
Gloucester refused to be deterred though and they rumbled over through another lineout drive.
Hastings converted to a huge roar, making it 35-30 with just five minutes to go.
And though Saints almost pieced together another breakaway try, there was to be no way back for Boyd's side.
Gloucester: Moyle (Rees-Zammit 62); Carreras, Seabrook, Twelvetrees, Thorley; Hastings, Meehan (Chapman 62); Elrington (Rapava Ruskin 53), Socino, Balmain; Clarke, Alemanno; Reid, Clement (Craig 62), Ackermann (c) (Davidson 77).
Saints: Hutchinson; Skosan, Proctor, Dingwall (Grayson 75), Collins (Francis ; Biggar, Mitchell; Iyogun, Matavesi (Haywood 75), Painter (Carey 76); Ribbans, Ratuniyarawa (Nansen 67); Coles, Wilkins (Tonks 64), Augustus.
Referee: Ian Tempest