MONTREAL — Even Canadian teenager Denis Shapovalov was amazed he had beaten tennis superstar Rafael Nadal.

The 18-year-old from Richmond Hill, Ont. shocked himself, the crowd that roared with every point he scored, and the tennis world with his 3-6, 6-4, 7-6 (4) victory over top-seeded Nadal in the third round of the Rogers Cup on Thursday night at a sold out Uniprix Stadium.

Shapovalov dropped to the ground and covered his face in joy and surprise as the cheers reached deafening levels after the match point fell, completing his comeback from a 3-0 deficit in the third-set tiebreaker.

"It’s what I dreamed of all my life growing up, playing guys like Rafa (Nadal), Roger (Federer), Andy (Murray)," said Shapovalov. "You know, my dream came true today."

The victory put him into a quarter-final Friday against France’s Adrian Mannarino, who beat Hyeon Chung 6-3,6-3.

It was one of the biggest wins in Canadian tennis history and it came at the tournament that some still call the Canadian Open.

Shapovalov became the youngest player to reach the tournament’s quarter-finals since Bjorn Borg in 1974.

He also became the youngest quarter-finalist at a Masters Series tournament ever and is the youngest to beat a player ranked in the top two in the world since Nadal beat Federer in 2004 in Miami.

Shapovalov will reach his goal of moving into the top 100 in the world in a week that saw him save four match points in a first round win over Rogerio Dutra Silva, then beat 2009 U.S. Open winner Juan Martin Del Potro in the second round before toppling Nadal.

"I’m very thankful that I’m in this position," said Shapovalov, who had hockey great Wayne Gretzky and Olympic swimming star Penny Oleksiak cheering for him from the seats. "If I didn’t save those four match points in the first round, there wouldn’t even be a chance to play Juan Martin or Rafa.

"It’s difficult to say how I was feeling during the match. It was extremely hard physically and mentally. Rafa is such a warrior. I’m just so happy to come out with the win."

Nadal, who could have claimed the No. 1 ranking if he had reached the semifinals this week, said it was the worst match he played all year, but he had kind words for Shapovalov.

"He played well," the 31-year-old said. "He has a great potential.

"I wish him the best. He has everything to become a great player. He played with the right determination in the important moments."

Shapovalov looked unfazed in facing the biggest opponent of his young career. After Nadal cruised through the first set, Shapovalov kept battling, breaking service while taking a 3-0 lead in the second. When Nadal would start taking a control of a game, the younger of the two lefthanders would respond with big serves or impressive forehands down the lines.

Nadal fought off two break points to hold serve at 4-2, then earned his own break to win back the momentum from the 2016 Wimbledon junior boys champion, only to see Shapovalov snatch it back and clinch the second set.

The two held serve through the third. Nadal went up 3-0, but Shapovalov used two aces to fight back and complete the upset victory over the 10-time French Open champion.

Second-seeded Roger Federer, a 4-6, 6-4, 6-2 winner over Spain’s David Ferrer, isn’t one to gloat over his stunning record against Spaniard, who was ranked third in the world in 2013.

Without playing especially well, the 19-time Grand Slam champion from Switzerland stretched his career record against the Ferrer to 17-0. It started with a win in Vienna in 2003.

"Maybe in the beginning he was not as good as he is now," Federer said of Ferrer. "Maybe I won five times because I’m better than he was.

"I was No. 1 in the world. I played him on hard courts also. I didn’t play him often on clay. Also, there were many tight matches, so maybe it became a mental thing for him. I have a lot of respect for David. As a person, he’s very nice. He’s a great fighter on the court. So this type of head-to-head is a bit strange."

In Friday’s quarter-finals, second-seeded Federer will face 12th-seeded Roberto Bautista Agut of Spain, against whom he is 6-0. Bautista Agut outlasted Frenchman Gael Monfils 4-6, 7-6 (5), 7-6 (2) in a two hours 56 minutes battle.

Unseeded Argentine Diego Schwartzman posted a strange win over American Jared Donaldson 0-6, 7-5, 7-5 to advance to a quarter-final meeting with Robin Haase, the 52nd-ranked Dutchman who upset seventh-seeded Grigor Dimitrov of Bulgaria 7-6 (3), 4-6, 6-1.

Kevin Anderson of South Africa downed American Sam Querrey 6-4, 6-1 and will next play fourth-seeded Alexander Zverev, who ousted 16th seeded Nick Kyrgios 6-4, 6-3.

Federer, who breezed past Canadian Peter Polansky in the second round on Wednesday, looked lost in the opening set, spraying balls long, wide or into the net, but gradually rediscovered at least some of the form that has seen the 36-year-old Swiss put back the clock with two grand slam wins this year.