Almagro had to pull out of a match against Rafael Nadal in May after less than half an hour with a knee injury.
The Spaniard appeared to have recovered fully and made it through a four-set match in the first round, beating Cyprus' Marcos Baghdatis.
And he had battled back from a set down to Del Potro to level the match at 1-1 before he was forced out of the tournament in the third game of the third set by an apparent recurrence of his knee problem.
When the 31-year-old, who is a three-time quarterfinalist at Roland Garros, realised he would have to throw in the towel, he collapsed in tears at the back of the court.
French Open prize money Fri, May 26, 2017
How much are players set to win at this year's French Open? As with all the Majors, men and women earn equal prize money at Roland Garros
Play slideshow AFP/Getty Images 1 of 8
But Del Potro was one of the first to his side, the Argentinian encouraging the crowd to get behind the stricken player.
The 28-year-old has endured his own injury problems and missed two years of of action with a wrist problem.
Perhaps recognising a kindred spirit, Del Potro helped a fuming Almagro to his chair.
The world No30 even packed his defeated opponent's bag for him and both left the court to loud cheers from the Roland Garros crowd.
Nicolas Almagro had to retire against Juan Martin del Potro at the French Open
Del Potro will now play either Andy Murray or Martin Klizan for a place in the fourth round.
"I wish you a speedy recovery [Nicolas Almagro]," Del Potro said on Twitter.
Get Quotes on Home Insurance
"I imagine what you feel.