Owen Williams kicked Gloucester to a tense and dramatic Aviva Premiership victory over west country rivals Bath at the Recreation Ground.
Wales international Williams converted Ed Slater's try five minutes into stoppage-time as Gloucester triumphed 22-21 and claimed a first away win of the season.
Bath wing Semesa Rokoduguni looked to have done enough for Bath when he crossed four minutes from the end of normal time for his second touchdown, but Gloucester were not to be denied.
Fly-half Rhys Priestland added three penalties and a conversion for Bath after scrum-half and captain Willi Heinz scored two tries to build foundations for what ended up being only Gloucester's second win from their last 11 Recreation Ground visits in the Premiership.
Williams chipped in with a penalty and two conversions as Bath struggled to build on an impressive European Champions Cup success against the Scarlets nine days ago.
Rokoduguni, who has been overlooked by England head coach Eddie Jones for this season's autumn Tests, claimed a quality first-half try for Bath, yet the home side offered little in attack apart from centre Jonathan Joseph's dancing feet and an occasional Anthony Watson break.
Gloucester, who had not won on their travels since a European Challenge Cup semi-final victory over La Rochelle last season, stunned Bath by taking a fifth-minute lead.
Bath had made all the early tactical probing, but Gloucester cut loose through a superb break by centre Henry Trinder that caused panic in the opposition defence, and Heinz applied a high-class finish to put the visitors 5-0 ahead.
Bath, though, showcased their attacking flair nine minutes later, securing quality set-piece possession before Joseph broke free inside his own half, found England colleague Watson in support, and Watson's pass freed Rokoduguni, who collected a sixth Premiership try this term.
Gloucester continued to find themselves under pressure territory-wise, yet they restricted Bath to a Priestland penalty before Watson went off for what appeared to be a head injury assessment.
He was on the receiving end of a questionable tackle by Gloucester wing David Halaifonua, although it went unpunished by referee Tom Foley, and as Watson departed, Priestland sent a long-range penalty wide when the visiting forwards infringed.
Bath trooped off at half-time with a three-point advantage, but it should have been much more of a lead, given their dominant field position and superior possession statistics.
While Watson then returned for the second period, Bath's England squad flanker Sam Underhill did not appear and was replaced by Matt Garvey.
Williams kicked a 46th-minute penalty to draw Gloucester level, and after Priestland landed a long-range strike, the visitors claimed a second try to regain the lead.
Prop John Afoa played the key build-up role, powering into the heart of Bath defensive territory before delivering a quality one-handed pass that Heinz gathered before surging clear and completing his double.
Williams' conversion made it 15-11 to Gloucester, only for Priestland to complete his penalty hat-trick after Ben Morgan was punished for a high-tackle on Bath flanker Zach Mercer.
It meant that an otherwise unconvincing game was at least set for a tense finish.
Rokoduguni looked to have seen Bath home following a barnstorming Taulupe Faletau charge, with Priestland converting, but then came the late drama.