Rafael Nadal resisted a late rally from Denis Shapovalov to beat the Canadian in a gruelling five-set thriller in the quarterfinals of the Australian Open on Tuesday to keep his quest for a record 21st Grand Slam title alive.

The Spaniard was two sets up and seemed to be breezing into his seventh semifinal in Melbourne before the world number 14 Canadian mounted a fightback to wrestle his way back to parity. Nadal also seemed to be bugged by stomach problems in the third and fourth sets. 

But following a seven-minute break between the last point of the fourth set and his first serve in the fifth, he recovered sufficiently to hold and then break Shapovalov’s serve for a 2-0 lead in the decider.

He held onto the break and when he clinched the match, Nadal went to the corner and nodded his head a few times and did a subdued fist-pumping celebration. Then he went back on court and properly celebrated. Shapovalov left a shattered racket on the court.

“I was completely destroyed. Tough day. Very warm,” Nadal said. “At the beginning of the match I was playing great (but) Denis is very talented, very aggressive. He was serving huge — especially the second serve.

“I think I had my chances at beginning of the third. I didn’t get it. I started to feel a little bit more tired. For me, it’s amazing to be in the semifinals.”

Nadal is level on 20 Grand Slam titles with Roger Federer and Novak Djokovic, with neither of his ‘Big Three’ rivals in Melbourne. 

Nadal has clinched the title only once, in 2009, and lost seven of his previous 13 quarterfinals — by far his worst conversion rate at any of the four major tournaments.

The men’s semifinals are both scheduled for Friday, giving Nadal two days off.

“I’m not 21 anymore!” he said. “After this . . . great to have two days off.

“I felt quite good physically in terms of movement. At least it was a great test. I really believe I’m going to be ready for the semifinals.”

Nadal will play either seventh-seeded Matteo Berrettini or No. 17 Gael Monfils. Berrettin was a Wimbledon runner-up last year; Monfils is 35 and contesting his second quarterfinal in 17 trips to Australia.