Three Weir penalties to two from opposite number Tom Heathcote had given the Warriors a 9-6 lead at the interval.
Heathcote struck two more to give Bath a three-point lead before full-back Stuart Hogg broke over in the 60th minute for the game's opening try.
The game remained in the hands of the kickers however and Bath looked set to snatch the victory as replacement Stephen Donald, playing his first game since winning the World Cup final with New Zealand, nudged over a penalty in the 77th minute.
But Gray had the last word to ensure both Scottish teams opened their Heineken account with victories raising hopes of a first knockout appearance since Edinburgh made the quarter finals in 2004.
There was also a clean sweep for the Welsh regions with the Scarlets, Ospreys and the Blues picking up victories while only Connacht failed to avoid defeat out of the four Irish regions but did themselves proud with their performance against unbeaten Premiership leaders Harlequins.
Italian teams Aironi and Treviso also tasted defeat against English opposition with defeats to Leicester Tigers and reigning Premiership champions Saracens respectively.