TORONTO, Canada - American Sofia Kenin scored her first victory over a Top 5 player in a big way at the Rogers Cup on Tuesday: with a 6-7(5), 6-3, 6-4 upset of World No.1 Ashleigh Barty in the second round.

The World No.29 had been 0-3 against Top 5 players and 0-3 against Barty entering the match, but nonetheless managed to pull off a three-set victory in just under two hours after nearly seeing Barty rally from deficits in all three sets.

"I think it was overall a really good match. I've played Ash a few times so I know her game style well, but I think I prepared myself better this time," Kenin told WTA Insider after the match.

"I went into the court and tried to already get adjusted to the game, because she plays very differently to other players. That's why she's No.1. The first set didn't go my way, but I was playing against the World No.1, so of course she was going to come up with amazing serves, start playing better and pick up her game.

"I just had to rewind, forget about it and just battle out there."

Kenin needed four match points to seal victory, as a double break advantage in the third set became just one, before Barty saved three match points in the ninth game to force the 20-year-old to serve for the upset.

Related: No.1 Scenarios: Barty loss opens door for Osaka, Pliskova in Toronto

She becomes the youngest American to defeat a reigning No.1 in eight years, since Christina McHale beat Caroline Wozniacki at the Western & Southern Open in Cincinnati, and becomes just the second American aged 20 or younger to beat a World No.1 in the past 18 years.

Earlier in the match, the American led by a break for much of the opener, but was unsuccessful in her attempt to serve out the set at 5-4, and later fell behind as the World No.1 opened up a 5-1 lead in the tiebreak before winning it on her third set point.

In the second set, Kenin again shot out of the gates by building a 4-0 lead, but Barty looked to bring the match under her control as she won three straight games to get back on serve.

Unlike the first, however, Barty was not able to consolidate her comeback effort, and lost eight of the last nine points to be taken to a final set.

The American again was the first to break serve in the decider, as she built a 0-40 lead and took her third opportunity to move ahead 2-1 and added a second break of serve to build another 4-1 lead, before holding the Aussie off down the stretch.

"I usually don't start off so well, and usually the first set goes by pretty fast. It takes me a while to find my rhythm against her," Kenin said.

"She plays very different and it is very effective. On any surface, when you're playing Ash especially, she plays amazing on all surfaces, there's no surface that she plays bad. 

"Whenever you play her, Ash is going to give everything and luckily, it just went my way today."

Barty, playing her first tournament since a fourth round loss to Alison Riske at Wimbledon, had won all three of her previous meetings with the rising American entering the match.

That head-to-head success included two wins this year, with a three-set victory in the round of 16 at the French Open en route to her first Grand Slam title.

"I think every match I've played Sofia they've been in different conditions. I've played her twice on clay and once on indoor hard. I think these conditions are very different. The conditions here are very unique," Barty said in defeat. 

"I think today I wasn't able to adapt quickly enough or well enough to play a match of the standard that I expect myself to play and I want myself to play. Sofia served today in the big moments. She served particularly well and got a lot of free points.

"I think these are courts where you need to be aggressive. You need to be confident and trust yourself and really hit through the ball, and today I didn't have quite enough of that. And against a player like Sofia, who hits the ball so cleanly and so aggressive and takes it so early, that's something you need.

"It wasn't there today, but she played an exceptional match when she needed to, and in the big moments she played some really good stuff."

Kenin will next face the winner of the match between a former World No.1 in Victoria Azarenka, and Ukrainian teenager Dayana Yastremska for a place in the quarterfinals.

"My confidence level is high. I'm playing well and having a good year. I love the big stages. I love the big matches. That's why I play...just being there, that's why I work hard," Kenin said. 

"I'm just really grateful and really happy that I've had some of these