Lee charged out of the blocks to raise Malaysian hopes of a first ever Olympic gold medal but Lin dug deep for a 15-21 21-10 21-19 victory in a 79-minute classic, denying his long-time rival in their second successive Games final.
World number one Lin had trounced Lee to win an emotional gold medal on his home court in Beijing four years ago but on Sunday he had to survive withering pressure from the Malaysian in the frenetic atmosphere of Wembley Arena.
In the deciding game, Lee lost the final point when he pushed a lob past the baseline, sending Lin into a frenzy and giving China their fourth badminton gold medal of the Games.
Cai Yun and Fu Haifeng later won the men's double title to give China a clean sweep of the five London badminton golds.
"My mind is blank right now. I am very, very happy," a joyous Lin told reporters. "This medal is confirmation of all my hard work since 2008. It is very tough being a Chinese player because we work so hard and sacrifice so much."
Badminton has been rocked by a match-throwing scandal that saw eight players disqualified from the London Games but Lin said he hoped his epic final against the Malaysian would show the sport in a good light.
"I really hope badminton isn't affected by the disqualifications in this tournament. This medal is a confirmation of the sport. I hope that my performance and Lee's performance today is evidence of that," he said.
A distraught Lee fell to the floor after the final point. He had been determined to give his country their first Olympic gold medal.
"I apologise to all the Malaysian people. I wanted very much to win the first ever gold medal for my people," he said.
"I only prepared for two weeks because of injuries and had to take pain killers to play. I fought hard and I gave all my best to try to win.
"I worked very hard but what is done is done."