Gloucester substitute Shane Monahan scored a hat-trick to help overcome a persistent London Irish at Kingsholm.
Tries from Sione Kalamafoni and Charlie Sharples put the hosts in control.
Monahan touched down either side two Marland Yarde efforts for London Irish to make it 22-12 after the break.
Yarde grabbed his third try, Gareth Ellis crossed and Ian Humphreys slotted a penalty to edge the Exiles in front only for Monahan to help seal victory by completing his own treble late on.
Monahan was on as a 10th-minute replacement for Gloucester's captain, England centre Billy Twelvetrees, who went off with an ankle injury.
Freddie Burns' second penalty of the afternoon had put the hosts back in front eight minutes from time.
He then converted Monahan's final effort before Myles Dorrian kicked a consolation penalty in the final minute for the visitors.
But Gloucester's hopes of finishing seventh and claiming a European Champions Cup play-off place have gone - on a day when Twelvetrees suffered an injury that could make him a doubt for England's Test meeting with the All Blacks in New Zealand.
Twelvetrees converted Kalamafoni's first-minute try only to leave the field after Sharples had added Gloucester's second try on nine minutes.
Yarde showed great speed to respond, before Gloucester suffered more injury woe on 24 minutes when Sharples was also forced off.
But Monahan extended the hosts' lead by diving into a ruck near the line.
The hosts were reduced to 14 men when Jimmy Cowan was sin-binned for back-chat, and Humphreys helped Yarde capitalise by setting the England international up for his second first-half try.
Mike Tindall broke away to then set Monahan up for his second try early in the second half, beating Yarde to touch down.
Ellis drove through for a third Irish try before Burns stuck a 30-metre penalty for the hosts.
Winger Yarde again linked up with Humphreys to cross for the bonus-point fourth try.
Humphreys put the visitors ahead for the first and only time with a penalty from right in front of the posts, having also converted two early tries.
Burns then slotted a penalty from near the halfway line to restore the hosts' lead.
While Dorrian booted another late penalty for the Exiles, Monahan's converted hat-trick try and a late Burns penalty denied the visitors a second losing bonus point to see the Cherry and Whites home.
Gloucester director of rugby Nigel Davies told BBC Radio Gloucestershire:
"We put a lot of effort into that game. There was a lot of passion. There are obviously a lot of players leaving at the end of the year.
"The boys stuck in there and we worked hard. We came through with a result. That was an absolute must-win game for us.
"You've got to say that they've got a pretty special player in Marland Yarde. When he gets the ball anything can happen.
"It was good to see Shane Monahan back. He finished his tries well, but he was a bit rusty in other areas."
London Irish director of rugby Brian Smith:
"Marland Yarde is an outstanding back three player but there are a lot of them in England. That was about his best game all season. He was magnificent. He will be sorely missed. He is genuine and a real competitor.
"There have been times when Marland has struggled to get back into the side after injuries because someone else has scored three tries.
"We knew they were going to play the game from deep and so we wanted to put all our defenders up in the front line and mug them.
"We worked really hard on getting a good start to shut the crowd up because that is a factor at Kingsholm - but life had something different in store for us."
Gloucester: Cook; Sharples, Tindall, Twelvetrees (capt), May; Burns, Cowan; Thomas, Edmonds, Puafisi; Stooke, James; Kalamafoni, Kvesic, Morgan.
Replacements: Monahan for Twelvetrees (10), Meakes for Sharples (24), Murphy for Y Thomas (55), Young for Kvesic (64).
Not Used: George, Knight, Savage, Robson.
Sin Bin: Cowan (36).
London Irish: Homer; Yarde, Mulchrone, Sheridan, Fenby; Humphreys, O'Leary (capt); Parr, Stevens, Halavatau; Gough, Rouse; Low, Sinclair, Hala'ufia.
Replacements: Mayhew for Stevens (55), Lewington for Homer (62).
Not Used: Smallbone, Hagan, Evans, Ellis, Dorrian, Allinson.
Referee: Steve Lee (RFU).