Malaysia's world number one Lee played a full part in an epic contest but was unable to avenge his defeats in the finals at Beijing 2008 and last year's World Championships.
Lin's victory, completed in 79 energy-sapping minutes, made him the first man to retain an Olympic Games Singles title and kept China on course for a clean sweep of Badminton golds.
Some of the rallies were extraordinary, with both players fully committed in defence and attack.
Lee is such a brilliant rival. This is quite lucky for me. I treasure the opportunities to play against him.Lin Dan
Lee, who in any other era might have won a handful of major titles, started superbly in his quest to finally get the better of Lin on the biggest stage.
But some unforced errors crept into his game early in the second set and allowed Lin to take the match into a decider.
Lee established an 8-5 lead and thought he had taken the next point, but a line judge was overruled on close call and the score became 8-6.
Lin quickly pulled level and the pair traded points until the Chinese snatched victory on his first match point and set off on a lap of honour.
The bronze medal was won earlier in the day at Wembley Arena by third seed Chen Long of China, who beat South Korea's Lee Hyun-il 21-12 15-21 21-15.
Lin said: 'Lee is such a brilliant rival. This is quite lucky for me. I treasure the opportunities to play against him.
'This gold again confirmed my hard work over the years, because I knew to get this again I'd have to work even harder.'
Lee, who was in tears on the podium, said: 'This is my second final with Lin Dan and I lost. I'm very disappointed I didn't win. I will do my best to work hard, and maybe win a gold.'