A single break of serve decided a cat-and-mouse opening set, Federer producing a sensational half-volley drop shot in the 12th game having put the Djokovic serve under serious pressure for the first time in the match.
With his Swiss fan club cheering on their man in a packed O2 Arena, the 34-year-old, 17-times grand slam champion pulled ahead in the second set with an early break, only to gift Djokovic the break back with a forehand error.
But world number one Djokovic was subdued throughout and failed to find the extra gear that he usually locates as Federer took advantage to move into a 5-2 lead.
Djokovic saved one match point after prevailing in a long baseline exchange but there was no escape a few points later when the Serb sent a forehand just wide to end their 43rd career meeting after one hour 17 minutes.
Djokovic, champion for the last three years at the O2 Arena showpiece, had not been beaten indoors since 2012, a winning streak of 38 matches.
Federer has two wins already in Stan Smith Group with Djokovic and Kei Nishikori, who was well beaten by the Serb earlier this week, on one apiece.
Djokovic will need to beat winless Tomas Berdych in straight sets on Friday to guarantee a semi-final place.