Nadal, who won a record 14 French Open titles during his 23-year career, had previously said he expected to retire this year after a hip injury that required surgery and limited his appearances in 2023.
The 38-year-old was a surprise selection for the Nov. 19-24 Davis Cup Final 8 in Malaga, after last competing at the Paris Olympics in July and subsequently missing the U.S. Open and Laver Cup over fitness concerns.
"It's been some difficult years, these last two especially," Nadal said in a video posted on social media.
"I'm very excited that my last tournament will be the Davis Cup representing my country. It's closing the circle because one of my first joys was the final in Sevilla in 2004."
Nadal has been no stranger to injuries and he sustained the hip problem at the Australian Open in early 2023 and missed the French Open later that year before having surgery.
He has played only 23 matches in the last two seasons.
Nadal returned to his favourite hunting ground this season but was beaten in the opening round by German Alexander Zverev and politely refused a celebratory farewell in the hope of a final hurrahnext year.
Dubbed the 'King of Clay' for his jaw-dropping 112-4 win-loss record at the Paris major, Nadal's last Roland Garros triumphcame in 2022.
Nadal will hang up his racket two years after great rival and Swiss maestro Roger Federer, leaving record 24-times major winner Novak Djokovic of Serbia as the only member of the 'Big Three' still active.
Federer led the tributes to Nadal on social media, saying that he hoped the day his friend announces his retirement would never come.
"What a career, Rafa ... Thank you for the unforgettable memories and all your incredible achievements in the game we love. It's been an absolute honour!" the Swiss great said.
Nadal thanked his family and his team for his stellar career, with a special word for his uncle Toni, who was his coach for most of his time on court.
"I believe that thanks to him, I have also been able to overcome many situations that have been difficult in my sporting career," he said.
To his fans, Nadal said: "I can't thank you enough for what you have made me feel. Everything I have experienced has been a dream come true."
"I leave with the absolute peace of mind having given my best," he added.
Nadal is now expected to receive what promises to be an emotional tribute at Roland Garros next year, with a similar celebration of his career expected at the Davis Cupon home soil.