Leeds secured a place in the Challenge Cup semi-finals but Championship side Leigh gave them a massive scare.
Ryan Hall's try put Leeds ahead but the Championship leaders stormed back and tries for Tom Spencer and Tom Armstrong stunned the Super League side.
Stevie Ward's score then brought the hosts level at 12-12 at half-time.
Leeds had to wait until seven minutes remaining to go ahead again when Robbie Ward dummied his way over and Zak Hardaker's try made sure.
It was tough on Leigh, who lost for the first time in 2014 and the defeat ended a run of 16 straight victories.
After Stevie Ward was denied a try because of a forward pass, Hall slid over in the left-hand corner for the game's first score, while Kevin Sinfield's kick made it 6-0 to Leeds.
But the Championship side quickly shocked the Rhinos with two tries in four minutes.
Spencer burst through and outmuscled Hardaker to score and, with Leeds all at sea at the back, Armstrong went over from Liam Kay's feed on the left side - both converted by Martyn Ridyard.
Leigh could have stretched their six-point lead further but Ryan Brierley dropped the ball at the vital moment, before Leeds' Liam Sutcliffe had a try chalked off for obstruction.
Sutcliffe's deflected pass then set up Stevie Ward to go over - a try given after lengthy scrutiny by video referee Robert Hicks - and Sinfield's conversion ensured the game was all square at the break.
Jamie Peacock of Leeds and Leigh's Matt Sarsfield were both shown yellow cards for fighting as the game exploded after the interval.
The second half was nip and tuck as both sides made numerous unforced errors and Leigh went so close to going in front, but Oliver Wilkes dropped the ball with the line at his mercy.
Leeds finally broken down Leigh's resistance and scored two tries in the final seven minutes to sneak through.
Robbie Ward burst through to put Rhinos ahead and Hardaker's try was a bonus, with Sinfield adding the extras for both scores and also adding a drop goal in between.
Leeds coach Brian McDermott:
"There would be an element of relief. It was a fantastic Challenge Cup game. That is what the cup is about - games like that.
"They would mix it with some Super League teams. They mixed it with us today so they would mix it with any Super League team.
"They had a level of intensity and determination that was Super League standard."
Leigh coach Paul Rowley:
"We didn't want to speak about being proud and putting on a good performance, we genuinely believed we could win.
"I'm as proud as ever but just disappointed because I don't like losing. We've got a winning culture.
"We'll get over the disappointment quickly but at the moment it is a bitter disappointment at not winning."
Leeds Rhinos: Hardaker, Briscoe, Watkins, Moon, Hall, Sinfield, Sutcliffe, Leuluai, R. Ward, Peacock, S. Ward, Delaney, Bailey.
Replacements: Singleton, Clarkson, Kirke, Walters.
Sin Bin: Peacock (43).
Leigh: McNally, Pownall, Higson, Armstrong, Kay, Ridyard, Brierley, Spencer, Penkywicz, Wilkes, Sarsfield, Haggerty, Barlow.
Replacements: Beswick, Emmitt, Goulden, R. Duffy.
Sin Bin: Sarsfield (43).
Referee: Ben Thaler