Eight-time champion Federer was level at 6-4, 6-7 (3/7), 3-6, 6-2 when Mannarino called it quits after just one point in the decider.
The Frenchman, celebrating his 33rd birthday, suffered a bad fall on the Centre Court grass in the seventh game of the fourth set.
Our heart goes out to you, @AdrianMannarino – it was a performance to be proud of and we wish you a speedy recovery… https://t.co/BxIpCSIizo
— Wimbledon (@Wimbledon) 1624989401000
Despite taking treatment from the trainer, he was hardly able to move and, grimacing in pain, had to retire.
“It’s awful and shows one shot can change the outcome of a match, season, career and I wish him all the best and hope we see him back quickly,” said Federer.
“He was the better player, he could have won, I got a bit lucky.
“That’s how it goes sometimes, you don’t get many walkovers and try not to have it happen to yourself.
“It’s a reminder how quickly it goes but I am obviously happy I can get another match here — I enjoyed myself today and it was great fun until the end.”
Just five weeks shy of his 40th birthday, Federer faces either Richard Gasquet of France or Japan’s Yuichi Sugita for a place in the last 32.
Federer fired 16 aces and 54 winners on Tuesday but will be concerned by committing 45 unforced errors.