Federer has been struggling with a knee problem for the last three years and, aged 41, has accepted defeat in his bid for one last hurrah.
He will play in next week’s Laver Cup in London, the Ryder Cup-style competition that was his brainchild, but will then leave the professional game.
Williams, who less than a fortnight ago bid her own farewell to the sport at the US Open, wrote on Instagram that she was among the “millions and millions” of people Federer had inspired throughout his 24-year career.
She said: “I wanted to find the perfect way to say this, as you so eloquently put this game to rest – perfectly done, just like your career.
“I have always looked up to you and admired you. Our paths were always so similar, so much the same. You inspired countless millions and millions of people – including me – and we will never forget.
“I applaud you and look forward to all that you do in the future. Welcome to the retirement club. And thank you for being you.”
Federer, who made the announcement on Thursday via a letter posted on social media, has not played a competitive match since losing to Hubert Hurkacz in last year’s Wimbledon quarter-finals.
The Swiss’ grand slam record has now been surpassed by both his great rival Rafael Nadal and Novak Djokovic but many, especially the fans he brought to the sport, consider him the best of all time.
A prodigious junior, the Swiss won his first grand-slam title at Wimbledon in 2003 and his last at the Australian Open four years ago in an unexpected three-slam swansong.
His remaining records include the most consecutive weeks at world number one with 237 and a run of 23 grand slam semi-finals in a row as well as his eight Wimbledon titles.
Federer’s influence on tennis will remain through the Laver Cup and the management agency he shares with long-time agent Tony Godsick, while it remains to be seen what else he will do in his retirement.
Nadal also paid tribute on social media, writing: “Dear Roger, my friend and rival. I wish this day would have never come. It’s a sad day for me personally and for sports around the world.
“It’s been a pleasure but also an honour and privilege to share all these years with you, living so many amazing moments on and off the court.
“We will have many more moments to share together in the future, there are still lots of things to do together, we know that. For now, I truly wish you all the happiness with your wife, Mirka, your kids, your family and enjoy what’s ahead of you. I’ll see you in London LaverCup.”