Federer’s loss means that Andy Murray will return to world number two when the new rankings are released on Monday, Federer dropping back to three.
"Actually, you know, to beat him, that was one of my goals for my tennis career," Nishikori said.
"And it happens on clay, it's amazing. You know it's not really my favourite surface."
After struggling with unforced errors in the first set, Federer appeared to have found his rhythm and range in the second when he lifted his level and completely dominated Nishikori in the second.
But a delay before the start of the third set, for the court to be watered, seemed to frustrated Federer and Nishikori took the opportunity to reverse the momentum.
Federer, playing in his first tournament since sustaining a back injury during the Indian Wells Masters seven weeks ago, looked unusually perplexed as to how to turn the match around.
Nishikori was in no doubt as to his game-plan, however, and remained consistently aggressive throughout, breaking in the fourth game of the final set before breaking again in the eighth game when Federer hit three consecutive forehand errors.
Nishikori will next play Spanish wildcard Pablo Andujar, who progressed to his maiden Masters quarter-finals when compatriot Daniel Gimeno-Traver withdrew at 5-5 in the first set.
"Credit to Kei he got it done and was more solid in the wind," Federer said.
"He played better than I did, so the better guy won today, that's for sure.
"I'll sit together tonight or tomorrow with the team and discuss what the plan is for the next few days and weeks.
"So I'm excited for that, because clearly I have no choice but to hit the practice courts."
The 31-year-old Youzhny had been pushed to three sets in each of his previous matches in the Spanish capital and was clearly struggling with the hangover from that.
Nadal, on the other hand, looked on a different level to the scrappy match that he produced in the second round; the Spaniard suffering just the one blip in concentration when he dropped serve mid-way through the second set.
But the two-times former Madrid champion quickly regained his composure and broke again immediately before cruising through the final two games and booking his place in the last eight.
"We are just doing what we can every day," Nadal said in an interview with Spanish television broadcaster La Sexta when asked about his physical condition.
"We are in the quarter-finals and it makes me very happy to have another chance to play in Madrid in front of these magnificent fans," the 26-year-old Majorcan added.
"It's not the time to be talking more than necessary. I will try to enjoy every moment as much as possible."
Nadal will face compatriot David Ferrer for a place in the semi-finals after the fourth seed was pushed all the way by resurgent Tommy Haas before triumphing 7-5 4-6 6-4.
Unseeded Grigor Dimitrov failed to follow up on his fine win over Djokovic when he surrendered a one-set lead and was beaten 3-6 6-4 6-1 by Stanislas Wawrinka.
The Swiss 15th seed next faces Frenchman Jo-Wilfried Tsonga, who came back from a set down to eliminate Madrid native Fernando Verdasco 4-6 6-3 6-2.
Third round results
3-Andy Murray (Britain) beat Gilles Simon (France) 2-6 6-4 7-6(6)
4-David Ferrer (Spain) beat 13-Tommy Haas (Germany) 7-5 4-6 6-4
14-Kei Nishikori (Japan) beat 2-Roger Federer (Switzerland) 6-4 1-6 6-2
7-Jo-Wilfried Tsonga (France) beat Fernando Verdasco (Spain) 4-6 6-3 6-2
5-Rafael Nadal (Spain) beat Mikhail Youzhny (Russia) 6-2 6-3
6-Tomas Berdych (Czech Republic) beat Kevin Anderson (South Africa) 7-6(5) 7-5
15-Stanislas Wawrinka (Switzerland) beat Grigor Dimitrov (Bulgaria) 3-6 6-4 6-1
Pablo Andujar (Spain) beat Daniel Gimeno-Traver (Spain) 5-5 (Gimeno retired)
- Sports & Recreation
- Pablo Andujar