Swiss tennis great Roger Federer announced his retirement from the sport on Thursday, saying next week's Laver Cup will be his final ATP tournament.

"As many of you know, the past three years have presented me with challenges in the form of injuries and surgeries. I've worked hard to return to full competitive form. But I also know my body's capacities and limits, and its message to me lately has been dear. I am 41 years old," Federer said on Instagram.

"I have played more than 1,500 matches over 24 years. Tennis has treated me more generously than I ever would have dreamt, and now I must recognize when it is time to end my competitive career.

"The Laver Cup next week in London will be my final ATP event. I will play more tennis in the future, of course, but just not in Grand Slams or on the tour."

The last of his 20 grand slam titles came at the 2018 Australian Open, with Novak Djokovic and Rafael Nadal both surpassing him in the roll of honour in recent years.

He won a record eight Wimbledon titles, six Australian Opens, five US Opens and one French Open.

Federer has not played a competitive match since losing to Hubert Hurkacz in the quarter-finals at Wimbledon last summer.

He subsequently announced he needed more surgery on his knee having previously undergone two operations in 2020 that kept him out for more than a year.

He had targeted a full return following the last operation but it became increasingly clear that his rehabilitation was not going as well as he had hoped.

Federer, who won his first grand slam title at Wimbledon in 2003, thanked his family for their support, writing: "I would like to especially thank my amazing wife Mirka, who has lived through every minute with me.

"She has warmed me up before finals, watched countless matches even while over eight months pregnant, and has endured my goofy side on the road with my team for over 20 years.

"I also want to thank my four wonderful children for supporting me, always eager to explore new places and creating wonderful memories along the way. Seeing my family cheering me on from the stands is a feeling I will cherish forever."

Federer's retirement, coming less than a fortnight after Serena Williams was given an emotional send-off at the US Open, is another indication that this momentous era in tennis is drawing to a close.

He continued: "I was lucky enough to play so many epic matches that I will never forget.

"We battled fairly, with passion and intensity, and I always tried my best to respect the history of the game. I feel extremely grateful. We pushed each other, and together we took tennis to new levels.

"Above all I must offer a special thank you to my unbelievable fans. You will never know how much strength and belief you have given me.

"The inspiring feeling of walking into full stadiums and arenas has been one of the huge thrills in my life. Without you, those successes would have felt lonely, rather than filled with joy and energy.

"The last 24 years on tour have been an incredible adventure. While it sometimes feels like it went by in 24 hours, it has also been so deep and magical that it seems as if I’ve already lived a full lifetime."

Concluding his letter, Federer wrote: "When my love of tennis started, I was a ball kid in my hometown of Basel. I used to watch the players with a sense of wonder.

"They were like giants to me and I began to dream. My dreams led me to work harder and I started to believe in myself. Some success brought me confidence and I was on my way to the most amazing journey that has led to this day.

"So, I want to thank you all from the bottom of my heart, to everyone around the world who has helped make the dreams of a young Swiss ball kid come true. Finally, to the game of tennis: I love you and will never leave you."

Federer won a record eight times at Wimbledon

A tweet from Wimbledon's official account read: "Roger, where do we begin? It’s been a privilege to witness your journey and see you become a champion in every sense of the word.

"We will so miss the sight of you gracing our courts, but all we can say for now is thank you, for the memories and joy you have given to so many."

The ATP Tour issued its own tribute to Federer, simply saying: "You changed the game, #RForever. "

ATP chairman Andrea Gaudenzi added: "Roger’s impact on tennis, and the legacy he’s built, are impossible to overstate. Over 24 years as a professional, Roger brought millions of adoring fans into the game.

"He spearheaded an incredible new era of growth and elevated the popularity of our sport. Few athletes have transcended their field in such a manner. Roger made us all feel proud and fortunate to be part of the same sport."

Federer's great rival Rafael Nadal paid tribute to the Swiss great, saying it had been a "privilege to share all these years with you."

"Dear Roger, my friend and rival, I wish this day would never have come," Nadal wrote on Twitter.

"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 at (the) Laver Cup."

Billie Jean King, who won 12 women’s singles grand slam titles, added her tribute to Federer on Twitter.

"Roger Federer is a champion’s champion," she wrote on her official account.

"He has the most complete game of his generation & captured the hearts of sports fans around the world with an amazing quickness on the court & a powerful tennis mind. He has had a historic career w/memories that will live on and on.

"Congratulations, Roger Federer. We wish you the very best as your journey continues."

Responding to Federer's retirement letter, Martina Navratilova wrote on Twitter: "What a heartfelt message, full of love, life, hope, passion and gratitude. Which is exactly how Roger played the game we love so much. Thank you thank you thank you, for all the magic!!!"

Rod Laver, after whom Federer named the Laver Cup, wrote simply: "Thank you for everything Roger. See you soon. Rocket"

Federer’s rivals also paid their tributes. Andy Roddick, beaten in three Wimbledon finals, wrote on Twitter: "Cheers Roger. Thanks for the shared memories my friend. It was an honour to share time/experiences on the most hallowed grounds in our sport. Don’t be a stranger.

Also, seems like a good time to start training for Wimby (Obviously kidding)."

Juan Martin Del Potro, the only player other than Rafael Nadal and Novak Djokovic to beat Federer in a grand slam final, said on Instagram: "You made tennis a unique sport.

"Thank you for teaching us with your example, in and out court. I’m thankful for sharing your journey and being able to play so many matches together.

"Thank you. Thank you for testing us all, raising our standards in every tournament we played, for everything you’ve given for our sport, for how warm you always were with me, and so many other things. I’m sad, this is something I didn’t want to hear. I do wish you a great life with Mirka and your kids."

Carlos Alcaraz appears set to carry the mantle as the new US Open champion and world number one, and he said on Twitter: " Roger has been one of my idols and a source of inspiration! Thank you for everything you have done for our sport! I still want to play with you! Wish you all the luck in the world for what comes next!"