Fokina stuns Ruud as Raonic falls to McDonald at Canadian Open
Ruud was two points away from victory at 5-3, 30-0 in Toronto before Fokina served his way out of trouble.
Still leading 5-4, the Norwegian had a chance to serve out the match but was unable to do so, badly shanking a shot on break point to hand the momentum to the Spaniard.
Both players held serve to send the contest to a tiebreak as the match crossed the three-hour mark.
Ruud dug himself into an early hole in the breaker with some tentative serving and poor forehands and Davidovich Fokina claimed the win with a drop shot.
"When I broke at 5-4, that gave me like a shot of tequila," the Spaniard said.
Up next for Davidovich Fokina is American Mackenzie McDonald, who reached his first quarter-final of a Masters 1000 tournament by dispatching Canadian Milos Raonic 6-3, 6-3.
After crushing 52 aces across his first two matches, hometown hero Raonic's biggest weapon proved his undoing.
He managed just nine aces to go with six double faults, some coming at the worst possible times including on set point in the opener and a break point in the second that put McDonald up 2-0.
Despite the loss, Raonic, a former world number three who returned to the tour in June after a two-year absence due to injury, said the tournament was a positive experience.
"A lot of things to look back and be proud of and to kind of look back with a smile," he said
"And just happy with how the week went overall."