The Swiss great, who was chasing a record eighth Wimbledon crown, was beaten 6-4 in the fifth set by Djokovic after saving a championship point and winning five games in a row to clinch the fourth 7-5.
"It was a great final. I can't believe I made it to five, it wasn't looking good for a while," he said on court afterwards.
"Going into a match with Novak, you know it's going to be tough. I can only say congratulations to him.
"It was an amazing match and an amazing tournament. It's well deserved."
For Djokovic, it is a second Wimbledon title and his seventh Grand Slam victory.