Federer, chasing a 17th Grand Slam, sealed a memorable 7-6 (7-5) 6-3 3-6 7-6 (7-5) win in three hours 39 minutes.
The 29-year-old Swiss edged a pulsating first set on a tie-break and took the second with a barrage of groundstrokes.
A clearly rattled Djokovic roared back in the third set but Federer, serving magnificently, was not to be denied.
The 2009 champion is into his fifth final at Roland Garros in the last six years, and on this resurgent form represents a serious threat to Nadal, so often his nemesis in Paris. A jubilant Federer said: “I was very confident, especially once I was up 7-6 4-1. I kind of felt like this match is not going to slip out my hands, even though I probably missed another 10 or 15 break points at the end of the second set.
“I just felt you don’t give me such a lead and then think you can crawl back into the match. I knew I was probably going to close it out.”
Djokovic, who came into the match unbeaten in 2011, had never been beyond the semi-finals before, but knew that another victory would see him replace Nadal as world number one and top the rankings for the first time. Federer, who was also the last player to beat Djokovic at the ATP World Tour Finals in London in November, added: “I wasn’t here to spoil the party. “I was just trying to put in a good match and get to the French Open final, which I’m obviously happy I was able to do. It almost feels like I’ve won the tournament, which is not the case.”
Djokovic, looking to equal John McEnroe’s record of 42 straight wins to start a season, had not played for four days because his quarter-final opponent Fabio Fognini withdrew because of injury but his lack of competitive action did not appear to affect his rhythm in the early stages of the match. Federer came out with all guns blazing, breaking Djokovic in the first game, but the 24-year-old Serb hit back immediately to level.
At this stage, the standard of play from both men was breathtaking, with the pair of them going toe to toe from the back of the court and producing some rallies of remarkable power and intensity. Federer was also trying to find some variety in his play, however, deliberately bringing Djokovic into the net and and it was a strategy that brought him some success. Djokovic applauded one pin-point Federer volley as the pair exchanged further breaks to remain level but it was the second seed who forced the first set-points at 5-4, which the 2009 champion saved with some stunning forehands.
They were only separated in a tie-break which, to the delight of the crowd on Court Philippe Chatrier, Federer took when Djokovic flopped a forehand into the net.
Federer piled on the pressure in the second set, continuing to attack with his returns while serving solidly to move 4-1 up. Still Djokovic battled on, saving five set points on his own serve at 5-2 and forcing a break-back point of his own in the next game before finally conceding it with another backhand into the net.
Federer had never lost any of the 174 Grand Slam matches where he had taken the first two sets but he did not have things all his own way on this occasion. Djokovic broke at the start of the third set and continued to improve, looking more like the invincible player he has been for the last six months.
The fourth set remained in the balance until the ninth game, when a shanked Federer forehand saw Djokovic break and serve to level the match, but Federer steadied himself to reply immediately. Both players survived some tense moments to take it to another tie-break, where Federer secured a crucial mini-break to move 4-3 up and consolidated it with two thumping serves.
With darkness falling at 9.37pm local time in Paris, Djokovic saved both match points on his own serve but an ace by Federer, his 18th of the match, saw him triumph.
Djokovic, who will still become number one if Federer beats Nadal, said losing “feels bad” but praised his opponent’s display, saying: “I think I had a good first set. I was really unfortunate to lose that set. After the first set I slowed down a little bit and he used that to take control of the match. “It’s definitely not easy to come back from two sets down against Roger but I tried to think about the first point of the third set as a new match.
“I think I played well but he played really well at the important moments. I congratulate him for a great performance. We were, I think, part of a very good match – BBC