Federer had swept aside six opponents without dropping a set en route to the final at Flushing Meadows, but his bid for an 18th major title was undone by Djokovic, who won 6-4 5-7 6-4 6-4.
It means the world number one has another US Open success to add to his first in 2011 and he moves just one short of Bjorn Borg in the Open era all-time list.
The 28-year-old has enjoyed a superb season, winning three out of four grand slam finals, and he now sits seven short of Federer’s record 17 major triumphs.
Federer stuck to his attacking guns in Arthur Ashe Stadium, hitting the net, releasing his rush-return and deploying as much variety whenever he possibly could.
But the Swiss was inefficient - converting just four of 23 break points - and eventually seemed helpless in the face of Djokovic’s masterful defence.
“That’s who Roger is - that’s why he has won so many grand slam titles,” Djokovic said.
“I knew that coming to the court. I knew he’s going to be aggressive. He’s going to try to disrupt my rhythm, and he’s going to put a lot of variety in his game.
“But I was ready for it. I was ready for the battle. That’s what it was - three hours, 20 minutes.
“We pushed each other to the limit, as we always do. It’s an ultimate challenge that I have now, winning against Roger back to back finals in Wimbledon and here, US Open.
“It’s tremendous. I’m really, really proud of it.”
Federer was not the only obstacle Djokovic had to overcome, as the champion withstood immense support for his opponent throughout the match.
At times passion spilled over into hostility, as some spectators jeered Djokovic’s shots and faults, which understandably agitated the Serbian, who ripped a button on his shirt after a particularly vociferous celebration.
“Obviously over the course of three hours 20 minutes match, you do have some ups and downs in concentration - you do sometimes let certain things distract you,” Djokovic said.
“But it’s important to get back on the course and go back to basics and remember why you are there and what you need to do.”
Djokovic added: “I accept the fact. Everybody has a choice to support a player that they want to support.
“He absolutely deserves to have the support he does because of all the years and success that he had and the way he carries himself on and off the court.
“No question about it. Me, I’m there to earn the support, and hopefully in the future I can be in that position.”
Federer only won two fewer points than Djokovic over the course of the match but committed 17 more unforced errors and was made to rue his 19 missed break points.
“I had too many break chances. Of course some of them I could have done better, should have done better, you know, all these things,” Federer said.
“There were a lot of opportunities missed. If it’s backhand, forehand, volleys, it doesn’t really matter at the end of the day.
“I know why I lost the match, very clearly - the moment I sat down at 5-2 down in the fourth or after the match was over.
“It’s something I will work on, and keep moving forward. It’s no problem for me.”
David Beckham led a pack of celebrities in the stands, with Robert De Niro, Sean Connery and Robert Redford all in attendance, but rain delayed the start of the match by three hours and it was not until 7.10pm the players finally emerged.
Djokovic had invited Scottish actor Gerard Butler into his box for the contest and the pair enjoyed an unusual exchange at the end of the match.
“We’ve known each other for several years and we are good friends,” Djokovic said.
“Funny enough, I actually sent him a photo and a message (on Saturday) night. I was watching the 300 movie so when I went to my box, I looked at him and I said, ‘This is Sparta!’
“It felt great. That’s one of the most inspiring movies I watched.”