Freddie Burns kicked 26 points as Gloucester beat Bordeaux-Begles to qualify for the quarter-finals of the Amlin Challenge Cup.
Two penalties from the England fly-half late on won it for Gloucester after they had trailed for much of the match.
Burns converted Darren Dawidiuk's first-half try and kicked eight successful penalties.
Bordeaux scored two tries, through Rafael Carballo and Tamato Leupolu, but Gloucester claimed a dramatic victory.
The French side took an early 11-3 lead after Carballo crossed early on, before Leupolu crashed over just before the break to cancel out Dawidiuk's effort to give the hosts a 20-19 advantage at half-time.
Bordeaux extended their lead after the break with two penalties from Lachie Munro, but the boot of Burns kept the Cherry-and-Whites in touch until they went ahead for the final time on 75 minutes.
Another successful kick from Burns in the final minute ensured Gloucester maintained their winning record in the competition with their fifth success in five games.
VIEW FROM THE DRESSING ROOM
Gloucester director of rugby Nigel Davies told BBC Radio Gloucestershire:
"It was very difficult coming here off the back of a poor performance last week. They have huge depth and it was really important to get a result.
"We made it hard - we let them have two soft tries in the first half just by falling off tackles and that really wasn't good enough. We were poor defensively in the first half. We had plenty of people to make tackles but we just didn't make them.
"I said when I came to the club we needed a goal kicker to get us into the play-offs and to start winning things and Freddie (Burns) is developing all the time.
"We've won five games out of six in a group with two Super 14 teams and one Aviva team. That's not a bad record and hopefully we can finish the job next Saturday."
Bordeaux-Begles: Munro, Carballo, Brousse, Denetre, Brana, Lopez, Seron, Poirot, Forbes, Leupolo, Chauveau, Tisseau, Gibouin, Kitshoff, Larrieu.
Replacements: Le Bourhis for Brousse (53), Serin for Seron (51), Labbe for Poirot (68), Rofes for Forbes (68), Decamps for Leupolo (51), Madaule for Gibouin (75), Chalmers for Kitshoff (69).
Sin bin: Chauveau (64).
Gloucester: Cook, Sharples, Trinder, Molenaar, May, F. Burns, Robson, Wood, Dawidiuk, Chistolini, Hamilton, James, Kalamafoni, Qera, B. Morgan.
Replacements: Knight for Chistolini (54), Edmonds for Dawidiuk (56), Murphy for Wood (56), Thomas for May (70), Tindall for Trinder (70).
Sin bin: Edmonds (57).
Referee: Andrew McMenemy (RFU).