Teenager Liam Sutcliffe denied Catalan Dragons their first win at Leeds with the last kick of a dramatic encounter.
Morgan Escare slotted a drop goal with three minutes remaining before Sutcliffe stole victory with a penalty.
A Zeb Taia brace, Escare and Eloi Pelissier tries had put Dragons in control at 24-14 in the second half.
Daryl Millard made it 30-30 for Catalans with Leeds' tries coming from Ryan Hall, Ben Jones-Bishop, Joel Moon (2), Josh Walters and Carl Ablett.
After Escare edged the French side ahead late on, the Dragons lacked composure to seal a momentous victory at Headingley.
The visitors lost possession from the restart when the ball failed to go 10 metres and conceded a penalty for obstruction while in possession in the last moments of the match.
Sutcliffe, 19, who came in as cover for injured captain Kevin Sinfield, held his nerve to land a 30-metre injury-time goal.
Escare gave the Dragons the ideal start, taking Leon Pryce's pass 30 metres out to cut through the Rhinos defence and step past Jones-Bishop for his 17th try of the season.
Sam Williams, making his first start for the Dragons, converted and went on to add a penalty goal after Hall had crossed in the corner for Leeds.
Jones-Bishop levelled proceedings at 8-8 by swooping on a Williams grubber-kick and racing away for an 85-metre try.
Tom Briscoe went close to putting Leeds ahead for the first time, but he failed to ground Sutcliffe's high kick.
Williams then created two tries in nine minutes, slipping the ball out of the tackle to get second rower Taia and hooker Pelissier over the line.
Jamie Peacock, making his 400th Super League appearance, found replacement forward Walters with a short pass and Sutcliffe's first conversion reduced the half-time margin to 20-14.
Taia brushed off a series of attempted tackles to complete his brace of tries three minutes after the break, only for Leeds to respond with two tries in nine minutes to level, Moon touching down out wide before Ablett forced his way over from close range.
Moon then pounced on a a stray pass from Pryce deep in Leeds territory to put the Rhinos ahead for the first time.
Pryce made amends by working a long pass out for winger Millard to go in for the Dragons' fifth try and Williams landed the touchline conversion to make it 30-30.
Williams failed with a long-range drop-goal attempt before Escare found the mark, only for Sutcliffe to steal victory.
Leeds coach Brian McDermott:
"It was a big moment in his [Sutcliffe's] career, holding his nerve like that. That wasn't an easy kick.
"That will be something he will look back on and have some memory of, how to handle those moments.
"I'm not happy at conceding 31 points, but we were playing a very good Catalan team.
"They're a form team, they have a huge amount of momentum behind them and I thought they performed better than us throughout the game. Certainly the full-back [Escare] caused us a huge amount of problems.
"So I'm comfortable with the win. We scored more tries than them and, while we weren't great and while I had resigned myself to the loss and we feel fortunate to have won, I'm not ashamed either.
Catalan Dragons coach Laurent Frayssinous:
"I'm disappointed not to go back to France with the two points but obviously I'm pretty happy with the performance. Scoring 30 points against the best defence in the comp means something for us.
"I thought we deserved more. We lacked smartness and composure in the last two minutes but it's hard to criticise any of my players because they had a dig.
"We need to keep on learning because it was the same at Widnes three weeks ago."
Leeds: Jones-Bishop, T. Briscoe, Watkins, Moon, Hall, McGuire, Sutcliffe, Singleton, C. Ablett, Peacock, C. Ablett, Delaney, Bailey.
Replacements: Achurch, S. Ward, Walters, L. Briscoe.
Catalan Dragons: Escare, Oldfield, Pomeroy, Duport, Millard, Pryce, Williams, Elima, Henderson, Lima, Taia, Whitehead, Baitieri.
Replacements: Anderson, Mounis, Pelissier, Garcia.
Referee: Robert Hicks (RFL)