Dubai - Former world No 1 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 qualifier Donskoy, 26, battled back to shock the third seed and set up a quarter-final clash against Lucas Pouille of France.
"There were so many chances, I'm trying to digest everything," said Federer who saw his eight-match win streak in 2017 ended by Donskoy.
Top seed Andy Murray said he was getting closer to his brilliant best as he hammered Guillermo Garcia-Lopez 6-2, 6-0 to surge into the quarter-finals.
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.
Fourth seed Monfils was motoring against the 43rd-ranked Evans, a finalist at the start of the season in Sydney, up a set and a break.
But the Briton lifted his game as he began a fightback to take the match level at a set each.
Monfils stepped up a gear in the decisive third set.
"It was a great match," he said. "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."
French seventh seed Pouille joined Monfils in the quarters, defeating Marius Copil 6-1, 6-4.
Second round results:
Andy Murray (GBR x1) bt Guillermo Garcia-Lopez (ESP) 6-2, 6-0
Evgeny Donskoy (RUS) bt Roger Federer (SUI x3) 3-6, 7-6 (9/7), 7-6 (7/5)
Philipp Kohlschreiber (GER) bt Daniil Medvedev (RUS) 6-4, 6-4
Lucas Pouille (FRA x7) bt Marius Copil (ROM) 6-1, 6-4
Fernando Verdasco (ESP) bt Roberto Bautista (ESP x6) 6-4, 3-6, 7-5
Gael Monfils (FRA x4) bt Daniel Evans (GBR) 6-4, 3-6, 6-1
Robin Haase (NED) bt Tomas Berdych (CZE x5) 3-6, 6-3, 6-4
Damir Dzumhur (BIH) bt Marcel Granollers (ESP) 6-3, 6-4