But fourth seed Federer broke back in the next game and seized the momentum when he blasted a cross-court forehand victor to break Krajinovic again and take the first set.
World number five Federer will now be up against Medvedev, who bounced back from a set down to clinch a 7-6 (5), 6-7 (5), 7-6 (0) triumph over American Reilly Opelka and seal a last-16 berth.
Medvedev was made to work harder for his win, spending almost two-and-a-half hours on court with Reilly Opelka and prevailing 7-6 (5) 6-7 (5) 7-6 (0).
"It was an. intense match in the first 10 games". "I have a lot of respect for those types of players who don't have the size, have to find a different way to win".
Federer broke back immediately and fended off a break point to lead 6-5, before avoiding a tie-break by fizzing a searing cross-court forehand victor past the Serbian.
Albot could not convert a break point in the deciding set tied at 3-3, and the Swiss took command from there to wrap up the match.
Federer needed three sets to defeat qualifier Radu Albot in the second round, but never looked like going the distance again once he overcame a shaky start. I'm happy I got it out of the way.
"I've played so many matches", the 18-year-old Canadian said.
Czech Kvitova, whose knife-wielding attacker in 2016 - 33-year-old Radim Zondra - was sentenced to eight years in prison yesterday, will play Australian Ashleigh Barty today after beating France's Caroline Garcia 6-3, 6-3.
Elsewhere, number six seed Kevin Anderson sunk Jaume Munar 6-4, 3-6, 6-3, while Stefanos Tsitsipas defeated lucky loser Mackenzie McDonald 7-6, 6-1.
Kvitova, a two-time Wimbledon champion, is ranked a career-high No. 2 and will rise to No. 1 if she wins the title.