The six-time champion overcame a two-set deficit to avert a monumental first-round upset, beating Alejandro Falla 5-7, 4-6, 6-4, 7-6 (1), 6-0.
Federer has reached the tournament final each of the past seven years, but Monday he barely survived the traditional opening match on Centre Court as defending champion.
Falla, ranked 60th, had lost all 11 sets in his previous four matches against Federer, but the Colombian played brilliant tennis to take charge of the match early. The turnaround came in the fourth set with Falla serving for the match and three points from victory, when Federer broke for only the second time.
He played his best tennis of the day after that. It was the sixth time Federer has won after trailing by two sets.
After winning the first two sets, Falla received treatment from a trainer during the next three changeovers for an upper left leg injury. But it was only when he served for the biggest victory of his career at 5-4 in the fourth set that his game unraveled.
Falla made shaky errors on the first two points, and a pair of deft forehands by Federer gave him the break. He ran away with the tiebreaker, taking advantage of four more unforced errors by Falla, and the disconsolate Colombian mustered little resistance in the final set.
There had been signs coming into the tournament that Federer might be vulnerable. He lost at the French Open this month in the quarterfinals, his earliest Grand Slam exit in six years. Then he dropped to No. 2 in the rankings behind nemesis Rafael Nadal. Then at a Wimbledon warm-up event came Federer's second grass-court defeat since 2003, extending his drought of nearly five months without a title.
But no one expected so much trouble against a 26-year-old journeyman who has yet to win a tournament. There were stretches of stunned silence from the crowd, dumbfounded by the score. Fans also roared in appreciate of Falla's frequent winners.
The match was Falla's third in the past four weeks against Federer, which at first worked to the Colombian's advantage. He kept Federer off balance by coming to the net often and made good use of crosscourt shots from the baseline.
The left-handed Falla was unfazed by Federer's serve, one of the sport's best, and repeatedly won points serving to Federer's backhand -- a tactic frequently employed by another lefty, Nadal.
Federer searched for more than two hours to find his championship form. He slipped several times on the immaculate lawn and shanked shots, hitting one forehand so wild that Falla had to leap out of the way.
Trouble for Federer began at 5-all in the first set. He had the first double-fault of the match on the opening point, then hit a poor volley and lost the next point. Falla dropped a backhand volley onto the baseline for a winner for the first service break, then served out the set.
Falla broke again for a 4-3 lead in the second set, then served out the set in a long, tense game.
Federer was 0-for-6 on breakpoint chances before putting a forehand winner on the line to close out the third set. He lost serve to start the next set, though, and found himself on the verge of defeat with Falla serving at 5-4.
Then Federer's big surge began. Barely 30 minutes later, he kissed the line with his final shot for a winner and walked to the net to give Falla a sympathetic pat on the shoulder.