(CNN) -- Kei Nishikori won a bruising three-hour contest against David Ferrer at the Miami Masters on Tuesday. He had plenty left in the tank when he faced a surging Roger Federer.
He didn't have to save any match points against the Swiss great -- the Japanese No. 1 fended off four of them to oust Ferrer, last year's finalist in Miami -- but Nishikori rallied to beat Federer 36 75 64 under the lights on Stadium court Wednesday.
The 21st-ranked Nishikori has now eliminated Federer twice in a row after upsetting the 32-year-old at the Madrid Masters in three sets last year.
"Feeling good, of course, to beat Roger," Nishikori told the ATP's website. "I thought I really played well, especially in the third. I was hitting both deep and striking well.
"Everything was going well. There (were a) couple of tough moments, but I was fighting through."
Federer entered the match as the substantial favorite despite the defeat in the Spanish capital, having returned to full fitness and finding his old form after a back injury hindered him for much of 2013.
He reached the final at the Indian Wells Masters earlier this month and there was a real possibility of the 17-time grand slam champion making the Indian Wells and Miami finals in the same year for the first time since claiming both titles in 2006.
"I could never really get my service games going," Federer told the ATP's website. "On the return, as the match went on, I think it was that Kei started to serve a bit better, which made it more difficult."
Nishikori became the first man to break Federer in this year's tournament, perhaps not a surprise since he is second only to Ferrer in percentage of return games won in 2014.
Still, Federer led by a break twice in the second set, only to see Nishikori -- whose career has been interrupted by arm and abdominal injuries -- break immediately back.
The lone break of the third set came in the final game.
"I think Kei does really well controlling the ball," said Federer. "He has great technique, especially on the backhand, very simple, very short back swings, so he does a really nice job of having good timing.
"I predict he's going to be in the top 10 in a short while."
Nishikori next faces Novak Djokovic, who defeated Andy Murray in straight sets.
World No. 1 Rafael Nadal, bidding for a maiden triumph in Miami, plays big-serving Milos Raonic and the in-form Alexandr Dolgopolov encounters Tomas Berdych in the remaining two men's quarterfinals.