The current world number one from Malaysia dropped to his haunches at 19-16 down and then tried to recover. (Agencies)
But he had to retire from the match at 20-17 – leaving Lin, who is world and Olympic champion, to take the title 16-21, 21-13, 20-17.
"It would appear that he suffered some cramps and he has subsequently been taken to hospital," said Gayle Alleyne, communications manager for badminton's world body the BWF at a press conference after the match.
Lee had been hoping to end a run of high-profile defeats at the hands of Lin -- widely regarded as the game's best-ever player -- who beat him in the previous world title men's singles final and in the two last Olympic finals.
Lin, 29, known as "Super Dan", was making his comeback at the tournament with a controversial wildcard place after a year on the sidelines to spend time with his family.
The two badminton legends put on a brilliant display in the first set in front of a packed Tianhe gymnasium in the southern Chinese city of Guangzhou.
"Both Chong Wei and I did a good job -- it's a pity he could not last until the end. He got this cramp out there and it reminded me of my training -- when you have that, you cannot move at all. From that moment we were not opponents any more. I really wanted to help and I went over to ask if he was OK. He didn't want to give up," Lin said after the match.
Lin's victory sealed a day in which China won only two of a possible four medals after sweeping all the titles at the last two world championships and at the London Olympics.
The current world number one from Malaysia dropped to his haunches at 19-16 down and then tried to recover.