Federer celebrated his 161st consecutive week as world number one last month, breaking the 30-year-old record of American Jimmy Connors, and was seeking his fourth title in a row at the Indian Wells Masters Series tournament.
Canas, 29, said after the match: "It's great to beat the number one, I feel perfect."
He outplayed Federer from the baseline, never allowing the top seed to control the centre of the court, and sealed victory with a powerful inside out forehand.
Canas, whose highest career ranking is eighth, returned to the tour in September after serving a 15-month suspension for a doping offence.
He lost in the last round of qualifying for the tournament to German Alexander Waske, but earned a place in the main draw when Belgium's Xavier Malisse withdrew due to injury.