Santoro had Federer rattled and irritable at times with a dazzling array of shot-making, but the Swiss found his best tennis when it mattered to advance to a meeting with Olivier Rochus, the 27th seed from Belgium.
"I had a blast out there today," Federer said. "Rarely the crowd gets into a match like they did tonight. The way he plays, the way I play, I knew it could be a great one."
The top seed looked on course for a comfortable victory when he stormed to a 5-1 lead but Santoro, the world number 76, broke back twice and Federer needed a third break, in the 12th game, to clinch the set.
The Swiss saved three break points in the seventh game of the second set before again breaking to win it, and then played a stunning tiebreak in the third, winning it 7-2 and ending up with an incredible 73 winners on the night.
"I could have closed it out earlier, but he played good tennis," Federer said. "The conditions were tough tonight, it was quite windy and it was tough to get it past him, particularly when he was coming to the net.
"He's tough to break because he has so many options. He mixes it up very well, that's the best part of his game."
Santoro, who hit some shots that left Federer smiling at their sheer audacity, said he had performed to his very limit.
"I can't play any better than I did tonight," he said. "I was a little nervous before the match because if you play even a little under your level against Roger then it's over in an hour.
"I was so happy to play a tiebreak in the third set and then in about two minutes the score was 6-0 for him."