The 27-year-old world number one also captured his fourth Indian Wells crown and is now tied with world number two Federer for the most men's titles in the California desert.
"The trophy is very heavy," Djokovic told the crowd as he celebrated adding to the titles he won in 2008 and 2011 as well as last year.
It was another epic struggle in a long list of hardcourt battles between the two top players in the world, who have met 38 times with Swiss great Federer still holding a slight 20-18 edge.
Djokovic had lost his last two matches to Federer in straight sets after beating him in last year's Wimbledon final.
The five-time Australian Open winner also needed three sets to beat Federer in the 2014 Indian Wells title match.
Djokovic's range of emotions Sunday went from shaking while trying to take a drink of water during a changeover, to breaking a racquet in fit of anger to the sweet bliss of beating the 17-time Grand Slam winner and one of the greatest of all-time on the big stage.
"If you look at the big picture, I thought I deserved it in an way, because I really fought for it," said Djokovic.
"I am at the prime of my career. I am going to use every part of this fact to stay where I am and to fight for as many major titles as possible.
"I don't think these challenges that I go through and the pressure that I feel are harming me or that I find it difficult. It is a privilege because I earned it."
Djokovic and Federer have combined to win eight of the last 12 Indian Wells titles but this is the first time they have met in back-to-back finals.
Federer insisted people shouldn't read too much into this loss.
"I have beat him the last couple times. It is not like I lost 10 in a row," Federer said. "A lot depends on how well he serves and returns. We usually play in finals so we are both peaking at the same time."
Djokovic blasted eight aces, 26 winners and broke Federer five times in the two hour, 17 minute battle in front of a crowd of about 15,000 inside the Tennis Garden stadium.
Surpassed coach Becker
Djokovic surpassed his coach Boris Becker (49) to become the 12th player in Open Era history with 50 ATP Tour titles.
Even though he had the crowd on his side, Federer couldn't overcome his poor serving and 43 unforced errors.
"Novak did well to sustain the lead for most of the match," Federer said.
"I think he found an extra gear in the end."
Djokovic jumped all over Federer's serve, allowing the Swiss to win just 15 points off the second serve.
"He (Djokovic) returns so well off the second serve," Federer said. "I am disappointed the end was flat from my side."
Federer's best moments came in the last half of the middle set when he broke Djokovic for the first time in the match to rally from an earlier break and level the set at 4-4.
Federer won the second set tiebreaker 7-5 but he got some help from Djokovic who made three double faults and then hammered a backhand long on set point.
But Djokovic broke Federer again early in the third to grab a 2-0 lead.
The Basel native got one back in a ten-minute third game that extended the epic battle to the two-hour mark.
The tight third game went back and forth until Federer won it on the fifth break chance after Djokovic slammed a backhand into the net.
"My best spell was midway through the second to midway through the third set," Federer said.
"It was disappointing to let it slip away."