It appeared that top-seeded Russian Medvedev had all the momentum when he eased through the first set tiebreaker and the temperamental Kyrgios smashed a ball into the stratosphere in frustration.
But the Australian regrouped and broke Medvedev's serve to begin the second set and served his way out of trouble in the following game for a 2-0 lead that he would not relinquish.
The match's pivotal moment came in the fourth game of the third set when Kyrgios raced from corner to corner to deliver a backhand that Medvedev could not handle, putting Kyrgios up a service break that sent the sun-soaked fans to their feet.
Kyrgios, who won 82% of his first serves, held at love in the final game to seal a place in the last 16.
"I knew he was feeling confident so I had to come out there with a game style that wasn't going to give him too much rhythm," Kyrgios told reporters. "I served and volleyed pretty much every point."
In other matches, Britain's Dan Evans stunned fifth seed Andrey Rublev 6-4 6-4 while the day kicked off with another upset as American Tommy Paul rallied to beat Spanish second seed Carlos Alcaraz 6-7(4) 7-6(7) 6-3.
Alcaraz looked to be heading for a victory when he bagged the first-set tiebreak before opening up a 4-1 lead in the second when his game inexplicably unravelled.
Alcaraz earned a match point during the second set tiebreak but once Paul saved it, the 19-year-old Spaniard's challenge faded.
"Right now all I can say, it was the first time that I couldn't handle the pressure," said Alcaraz.
"I felt the pressure to be the number two seed in this kind of tournament, number four in the world. It was the first time that I felt that pressure, and I couldn't handle it."
Also advancing in Montreal were Norwegian Casper Ruud, Australia's Alex de Minaur, Italy's Jannik Sinner, Croatia's Marin Cilic, Frenchman Gael Monfils and Spaniards Roberto Bautista Agut and Pablo Carreno Busta.