Wawrinka, seeded third, won 6-7 (1-7) 6-4 7-5 6-3 to add the US title to those he had already won in Australia and France over the last two years.
The 31-year-old hit 46 winners in a brilliant display of shot-making.
"My goal is to give everything I have to be the best I can," said Wawrinka, who saved a match point in the third round against Britain's Dan Evans.
"I never had a goal to win a Grand Slam but I am trying as best I can. Match after match I was playing better."
He required treatment for a blister on his big toe in the final set, prompting complaints to the umpire and tournament referee from Wawrinka as the interruption came before his service game.
"Stan, sorry! I can't stand," Djokovic shouted across to him during the break.
After the match, Djokovic said: "Congratulations, Stan, to your team as well. This has been absolutely deserved today. You were the more courageous player in the decisive moment and he deserves his title."