"I am really sad to announce that I have to withdraw from Roland Garros," Djokovic wrote on social media.
"I played with my heart and gave my all in yesterday's match and unfortunately, due to a medial meniscus tear in my right knee, my team and I had to make a tough decision after careful consideration and consultation."
Tournament organisers had initially announced his withdrawal, saying an MRI scan earlier on Tuesday had revealed the full extent of the injury.
World number one and 24-time Grand Slam champion Djokovic was due to play Ruud on Wednesday for a place in the last four. Djokovic defeated Ruud in straight sets in last year's final at Roland Garros.
As a result, Ruud will go on to face fourth seed Alexander Zverev or 11th seed Alex de Minaur in the semi-finals on Friday.
The 37-year-old Djokovic had cast doubt over his fitness following Monday's five-set win over Francisco Cerundolo, admitting he needed anti-inflammatory drugs to get through the match.
Djokovic blamed the "slippery" Philippe Chatrier court for the injury he sustained early in the second set of his 6-1, 5-7, 3-6, 7-5, 6-3 victory over Cerundolo.
"I don't know what will happen tomorrow or after tomorrow if I'll be able to step out on the court and play. You know, I hope so. Let's see what happens," Djokovic said after his record 370th win at a Grand Slam.
"For the last couple weeks I have had, I would say, slight discomfort, I would call it that way, in the right knee, but I haven't had an injury that would be concerning me at all.
"I was playing a few tournaments with it, and no issues until today."
Djokovic had already been tested to the limit physically by a gruelling four-hour, 29-minute slog against Lorenzo Musetti in the third round that concluded at 3:07 am Sunday morning, the latest finish in French Open history.
Preventable injury?
He had complained about the state of the clay in the match with Musetti, and did so again in the last 16, calling for the court to be swept more regularly.
"Could have this injury be prevented? "Possibly, if there was just a little bit more of a frequent care of the court," Djokovic said.
His withdrawal from the French Open means that Jannik Sinner will become Italy's first world number one next week.
"It's every player's dream to become number one in the world. On the other hand, seeing Novak retiring (from the tournament) is disappointing, so I wish him a speedy recovery," said Sinner.
Sinner advanced to his first Roland Garros semi-final shortly after Djokovic's exit from the competition, defeating Bulgarian 10th seed Grigor Dimitrov in three sets.
The Serbian star arrived at the tournament with his status at the top under threat from Sinner, who was guaranteed to supplant Djokovic if the latter failed to reach the final in Paris.
Djokovic has spent a record 428 weeks at the top of the rankings.
His injury extends his worst start to a season since 2018, when he didn't win an event until claiming the Wimbledon title.
Adding to his problems, he was accidentally hit on the head by a metal water bottle in Rome last month before suffering stomach problems in Geneva.
Djokovic last retired at a Grand Slam during the 2019 US Open, when a shoulder problem forced him to quit against Stan Wawrinka in the last 16.
He now faces a race against time to be fit for Wimbledon, which begins July 1st. Djokovic is a seven-time winner at the All England Club, one shy of Roger Federer's record.