Harlequins scored 15 points in the last nine minutes to record a 30-27 comeback victory and wreck Gloucester's European Champions Cup qualification hopes.
Gloucester looked sure-fire winners but a yellow card for hooker Richard Hibbard turned the game Quins' way to leave Gloucester nine points off sixth-placed Northampton with five league games remaining.
The hosts only had themselves to blame following an error-ridden performance where weak tackling and poor ball retention contributed to their downfall. Charlie Sharples scored two tries for Gloucester and David Halaifonua one with Billy Burns converting all three and adding two penalties.
Ross Chisholm, Charlie Mulchrone, James Chisholm and Tim Visser scored tries for Quins with Tim Swiel converting one and kicking a penalty. Lang added a conversion and a penalty.
Gloucester made an explosive start to take a third minute lead with a brilliant try after Harlequins lost possession five metres from the home line which allowed the hosts to counter-attack in style.
A long pass from Matt Scott sent Burns away down the left flank before the outside-half fed David Halaifonua with an inside pass.
The Tongan made 30 metres before sending Will Heinz on his way to the try-line only for Ross Chisholm to haul the scrum half down just short, but Sharples was on hand to pick up and score.
The home side went on to dominate the opening quarter but it was Harlequins who blew the best chance when strong runs from Visser and Joe Marchant took them deep into the Gloucester 22, but once again the visitors lost possession and the opportunity was lost.
However after 21 minutes, Quins did get on the scoreboard when a well-judged pass from Swiel saw Visser crash over in the corner.
Swiel missed the conversion but Gloucester were shocked by conceding a second try 10 minutes later.
Home number eight Ben Morgan lost possession on half-way and Quins made him pay by producing a flowing movement with Marchant and Ross Chisholm making crucial contributions to create the score for Mulchrone.
Swiel converted before he and Burns exchanged penalties to leave Gloucester trailing 15-10 at the end of an entertaining but disjointed first half.
Early in the second half, Quins suffered an injury blow when Mulchrone limped off to be replaced by Luc Jones before they lost their lead.
Mat Luamanu failed to take an up-and-under from Burns which allowed Jeremy Thrush to kick the loose ball ahead.
Matt Hopper seemed to have retrieved the situation by falling courageously on the ball but Gloucester recycled possession to leave Halaifonua with a stroll to the line.
Two minutes later, the hosts were over again when Hibbard exploited a gap on the blindside of a ruck before his neat pass created a second try for Sharples.
Burns converted and added a penalty before Swiel was off target with his penalty attempt to leave Gloucester with a 27-15 advantage going into the final quarter.
Quins looked to have reduced the arrears when Luamanu crossed but the TMO ruled that the scoring pass from James Chisholm was forward.
With nine minutes remaining, Hibbard was sin-binned and Quins immediately capitalised with James Chisholm brushing aside a weak tackle from Billy Twelvetrees to score.
A flowing movement involving Marland Yarde and Alofa Alofa then saw Ross Chisholm pick up a fourth try with Lang's last minute kick securing a dramatic victory.