Federer hasn't been eliminated in the second round of a tournament since the 2010 Rome Masters, and the 16-time Grand Slam champion had to call on his wealth of experience and shotmaking abilities to survive an early scare against the 23rd-ranked Canadian.
Federer, who was stretched to three sets in winning their only other meeting at Indian Wells earlier this season, recalled a past era when describing a fast-paced match full of power and passing shots.
"These are some of the fastest courts on tour, I expected that a few shots would decide the match, that's what it was like back in the days of (Pete) Sampras, (Boris) Becker and (Stefan) Edberg," Federer said. "That's the way it was tonight."
Raonic overpowered Federer's attempts to serve and volley early as he hit perfect passing shots whenever the Swiss star came forward. Raonic won 12 straight points to close out the first set, earning the decisive break in the ninth game.
Federer was on the back foot again to start the second, but the Swiss player's serve bailed him out repeatedly, helping him save all four break points he faced in the set.
"I thought I could take it to him by serving and volleying and it worked a bit," Federer said. "I definitely started to get a better read on his serve and to get into more baseline rallies, make him hit more shots on his own serve."
Federer secured the break he needed in the 11th game by stretching Raonic wide to send a shot into the net, and then clinched the set with a soft drop shot.
Both players held serve in the decider to force the tiebreaker, where Federer led 4-1 before a number of erratic shots from the Swiss player allowed Raonic to pull to 5-4.
But Raonic unleashed a wild forehand long to give Federer match point, and the third-ranked Swiss stroked a sublime crosscourt forehand to clinch the victory.
"I thought I played really well the whole time, I was doing what I wanted to do, I was dictating ... I just came up a bit short," said Raonic, who had 21 aces. "Tonight, it comes down to one point. It's hard not to be disappointed."
Unlike Federer, Nadal thrived on the surface that he criticized this week as soft and slippery, hitting six aces.
"I played much better than I expect," Nadal said. "The (blue) court ... doesn't make you feel comfortable. It's difficult, hard to attack and come back to defend. You just have to try and adapt."
"It has nothing to do with the courts, I just didn't play well," said Isner, who praised his Croatian opponent. "He has played better and he deserves to win."
The third-seeded Kvitova struggled with her serve against Hradecka. Kvitova was broken five times by Hradecka of Czeck republic, who will face Ekaterina Makarova in the third round. Makarova beat Maria Kirilenko of Russia 6-4, 6-4 to advance.
Errani failed to convert any of her eight break points as she showed little of the consistent play that carried her to three straight titles this season.