Fiji's Caucaunibuca was in irrepressible form for Agen
Agen: (14) 26
Tries: Elhorga, Mignardi
Cons: Miquel (2)
Pens: Miquel (4)
Gloucester: (5) 18
Tries: Balshaw, Richards
Pens: Lamb (2)
Agen shrugged off a Gloucester fightback to edge a feisty Heineken Cup clash at Stade Armandie.
The French side raced to a 14-0 lead with early converted tries from Pepito Elhorga and Arnaud Mignardi as they threatened to run away with the game.
But Gloucester showed patience and Iain Balshaw scored off Rory Lawson's clever blind-side break for 14-5 at half-time.
A Ryan Lamb penalty and Peter Richards' try gave Gloucester a 15-14 lead but four Agen penalties sealed the tie.
The victory took Agen second behind Leinster in pool two, while third-placed Gloucester still have a mathematical chance of qualifying, though they face the Irish province in their final game. Leinster play Edinburgh on Saturday.
Caucau is the best player I have ever played against
Agen set off at a thunderous pace and forced Gloucester to soak up some heavy early pressure.
But the dam burst on nine minutes when the classy Fijian Rupeni Caucaunibuca ran over Gloucester full-back Olly Morgan and released Mignardi to romp home.
Jerome Miquel converted and was on target again five minutes later when Elhorga rounded off a slick Agen counter-attack to score under the posts.
The home juggernaut was dented by the sin-binning of lock Wilhelm Stolz and then slowed further when Lawson launched a stunning raid down the short side and delayed his pass with perfection for Balshaw to score.
But Gloucester's renaissance was hit by a yellow card for England centre Mike Tindall on 36 minutes for entering a ruck from the side.
Miquel slipped taking the penalty, leaving the score at 14-5 but in first-half injury time Gloucester prop Christian Califano and Agen prop Laurent Cabarry were sin-binned for trading punches.
Both sides made a plethora of substitutions after the break but it was Gloucester who made the early inroads with a Lamb penalty on 56 minutes.
Gloucester began to exert more control up front and their improvement helped the backline turn the game on its head.
Moving to the right on their own try-line, full-back Balshaw took the ball at pace to feed James Simpson-Daniel, who beat two men on the outside before delivering a well-timed pass to Richards steaming up on the inside for the try.
Lamb's conversion gave Gloucester a slender lead at 15-14 and when Dave Vainqueur was sin-binned on 66 minutes, the young fly-half added a penalty from in front of the posts.
Agen closed the gap with a penalty inside the last 10 minutes but another Gloucester indiscretion gave Agen a 20-18 lead with five minutes left.
Gloucester went close through Simpson-Daniel's late mazy run, but they squandered a chance to pump the ball into the corner from a penalty, and were made to pay when a scuffle involving Lamb ended with three more points for Miquel.
Tindall also bludgeoned his way through the Agen line late on but the hosts clinched it with a fourth Miquel penalty.
Gloucester coach Dean Ryan:
"We are hurting. We got ourselves into a winning position but there was a little bit of inexperience and we gave away a few cheap penalties.
"The margins at the top end are very small and we've got to learn from that.
"You have to expend an enormous amount of effort just to find out the learning curve of the decision-making and we got ourselves back in on that effort.
"This is a good side. We wouldn't be competing at this level without it being a good side. But it's a small step to be a really good side and get in the mix in this competition."
Agen: Elhorga; Vainqueur, Ahotaeiloa, Mignardi, Caucaunibuca; Miquel, Morlaes (capt); Cabarry, Tiatia, Galasso, Stolz, Socol, Lievremont, Culine, Soucaze.
Replacements: Narjissi, Meeuws, Popescu, Yukes, Fulton, Faaletino, Stoltz.
Gloucester: Morgan; Simpson-Daniel, Tindall, Allen, Balshaw; Lamb, R Lawson; Califano, M Davies, Nieto, Bortolami (capt), Brown, Buxton, Hazell, Forrester.
Replacements: Azam, Collazo, James, Boer, Richards, Walker, Foster.