The Frenchman hurt his right knee in a fall during the fourth set and had to call it quits.
The Frenchman was two sets to one up and a break down in the fourth against a rusty Federer when he slipped under the Centre Court roof and hurt his right knee.
Mannarino tried to continue but was severely hampered and, after losing the fourth set while barely able to serve, called it quits at 6-4 6-7 (3) 3-6 6-2.
Playing under the roof appears to make the grass more slippery, med Novak Djokovic falling several times during his first-round match against Jack Draper on Monday.
Federer said: “It’s awful. It shows that one shot can change the outcome of a match, a season, a career. I wish him all the best and I hope he recovers soon. He could have won the match, he was the better player, so I got a bit lucky.
“You don’t get many walkovers throughout a career. I’m obviously happy I can get another chance for a match here. I worked very hard and I enjoyed myself out here until the end.”
Federer had focused his recovery from two knee operations on being fit for possibly a final tilt at a ninth Wimbledon title and he was good enough in the first set against a player who plays his best tennis on grass and had made the fourth round here three times.
Federer lost the first three points of the match on his own serve but thereafter had more of the chances and took the set with a vintage backhand pass.
But the sixth seed, som snur 40 in just over a month, has only played a handful of matches in the last year and a half and suffered a dispiriting loss to Felix Auger-Aliassime at the warm-up event in Halle.
Federer insisted in his pre-match press conference that he had put that match behind him but he began to make an increasing amount of errors as the second set wore on, particularly on the forehand side.
He played a poor tie-break to help Mannarino win just his second set in their seventh meeting, and the Frenchman was clearly the better player at the start of the third.
Federer would surely rather have faced a player less comfortable on the surface against whom he could exploit his grass-court wiles but it was Mannarino producing the magic and, although the eight-time champion recovered an early break, his opponent forged ahead again.
Federer had not lost in the first round at a grand slam since the French Open in 2003 but that looked a serious possibility, particularly when Mannarino forced another break point in the opening game of the fourth set.
Crucially, Federer saved it, and from there he began to appear more comfortable, stepping up his aggression and shortening the points.
Whether he would have completed the comeback became a moot point, with it immediately apparent that Mannarino’s slip was anything but innocuous.
He stayed down on the court for a couple of minutes before limping back to his chair and, although he received treatment, there was no way back.