MADRID — Rafael Nadal announced Thursday he will retire from tennis at age 38 following next month’s Davis Cup finals.

Nadal won 22 Grand Slam singles titles during an unprecedented era he shared with his rivals in the so-called Big Three, Roger Federer and Novak Djokovic.

“Really, everything I have experienced has been a dream come true,” Nadal said in an announcement on social media. “I leave with the absolute peace of mind of having given my best, of having made an effort in every way”

The Spaniard indicated his decision was related to persistent injury problems.

“The reality is that it has been some difficult years, these last two especially. I don’t think I have been able to play without limitations. It is obviously a difficult decision, one that has taken me some time to make. But in this life, everything has a beginning and an end,” Nadal said.

Nadal’s unrelenting, physical style of play — every point pursued as though it were his last, sprinting and sliding into place for that high-bouncing bullwhip of a lefty forehand — made him one of the greats of the game and the unquestioned King of Clay, the slow, red surface on which he claimed his record 14 French Open championships.

That’s more than anyone, man or woman, won at any one of the sport’s four major tournaments, a dominance celebrated by a statue of Nadal that stands near the main entrance to the grounds of Roland Garros and in the shadow of its main stadium, Court Philippe Chatrier.

Nadal added Thursday that he was excited to finish his career at the Davis Cup, which will be played in Malaga, Spain.

“I am very excited that my last tournament will be the final of the Davis Cup and representing my country,” he said. “I think I’ve come full circle since one of my first great joys as a professional tennis player was the Davis Cup final in Seville in 2004.”

Nadal has not played since the Paris Olympics, where he lost to old rival Djokovic in the second round of the singles tournament and reached the quarterfinals of the men’s doubles with Carlos Alcaraz.

“I think it is the appropriate time to put an end to a career that has been long and much more successful than I could have ever imagined,” he said.