Former world number one Federer, 35, who lifted his 18th Grand Slam title at the Australian Open in January, had match points in the second-set tiebreak and also led 5-1 in the third-set breaker.
But world-ranked 116 Donskoy battled back to stun the third seed and set up a quarter-final clash against Lucas Pouille of France with a thrilling 3-6, 7-6 (9/7), 7-6 (7/5) victory.
"I surprised everyone today. I think whoever wins against Roger surprises himself," said Donskoy 26.
"I can say it's a dream come true, but I don't like this because you always want to win, even if it's Roger."
It was just the third time since 2007 that Federer has been beaten by a qualifier.
"I just never really got going tonight and sort of felt heavy. But look, those matches happen frequently, where you just got to somehow find a way to come through," said the Swiss legend, who was chasing a record eighth title at the Dubai Championships.
"Tonight I was convinced that if I came through I was going to feel better tomorrow. I came (to Dubai) early. I was perfectly prepared, it's just a tough loss tonight. So many chances... It was crazy."
Federer, who saw his eight-match win streak in 2017 ended by Donskoy, did not want to make excuses and said it had nothing to do with a leg injury picked up at the Australian Open, where he beat old foe Rafael Nadal in the final in his last appearance before Dubai.
"I just think it's still the beginning of the comeback and I've got to take the positives out of playing again a tournament where I feel I'm quite healthy and I'm happy I got over the injury I sustained at the Australian Open," he said.
- Murray cruises -
==================
Top seed Andy Murray had no such trouble and said he was getting closer to his brilliant best as he hammered Guillermo Garcia-Lopez 6-2, 6-0 to surge into the quarters.
The world number one's rapid victory lined up a Thursday meeting with Philipp Kohlschreiber after the German beat Russian Daniil Medvedev 6-4, 6-4.
"It was very tough at the start, we both had chances in those early games," Murray, who has never won the Dubai showpiece, said.
"I played very well. I served better today than in the previous round. I'm certainly playing better than I did at the start of the year. Everything worked well tonight.
"I moved well and played offensive. I was focused throughout. I didn't give any cheap points away."
Murray and second-round victim Garcia-Lopez had not faced off since 2012, with the Spaniard winning their last meeting at Indian Wells.
But there was never a hint of a repeat.
After the first four games lasting half an hour, the pace picked up with Murray winning the first set.
He tightened his grip, losing just one point on his serve in the second set on his way to a dominant victory.
Gael Monfils held off Britain's hard-charging Dan Evans with a gutsy 6-4, 3-6, 6-1 victory.
The Frenchman is playing in the emirate for only the second time in his career after a first-round loss in 2008.
The world number 12 moves into a clash with Spain's Fernando Verdasco, who needed almost two and a half hours to overcome sixth-seeded compatriot Roberto Bautista Agut 6-4, 3-6, 7-5.
"It was a great match," said Monfils. "In the second set he started really going for his shots.
"I had to try and control him, I finally found a way to win."
source: AFP
GMT 07:22 2018 Monday ,22 January
Relieved Rafa survives test as Dimitrov ousts KyrgiosGMT 09:36 2018 Sunday ,21 January
FedExpress steams on as Sharapova grindsGMT 07:23 2018 Friday ,19 January
Djokovic survives brutal Melbourne heat testGMT 10:09 2018 Wednesday ,10 January
Federer eyes fresh 'fairytale' as Slam rivals struggleGMT 19:28 2017 Thursday ,23 November
Federer, Nadal set for repeat show in 2018?Maintained and developed by Arabs Today Group SAL.
All rights reserved to Arab Today Media Group 2021 ©
Maintained and developed by Arabs Today Group SAL.
All rights reserved to Arab Today Media Group 2021 ©
Send your comments
Your comment as a visitor