Federer, who was broken three straight times in the first set, came within two points of winning while leading 5-4 in the third set. But Davydenko held on and then broke Federer to take a 6-5 lead before serving out the win.
"I was a couple of points away, but just couldn't get it done," said Federer, a four-time champion at the season-ending event. "He did well. I thought he played strong throughout, even though I don't think it was our best match we ever played against each other."
It was the Russian's first win over Federer in 13 matches.
"All my family, everybody who supports me, wait for this moment, when I can beat Federer," Davydenko said. "I was thinking it coming maybe 2010 or '11. But in 2009, end of the season, it's good feeling."
Federer again struggled with his serve and his shot-making for much of the match, but he looked invincible throughout the third set, losing only three points on serve to hold easily through 5-4. And with Davydenko serving to stay in the match, Federer took a 30-0 lead when he returned an overhead smash from Davydenko by running across the court and jumping high to get his racket on the ball.
Davydenko was stunned by the acrobatic return, but he still won the next four points to hold serve.
"I was thinking, Federer again lucky," Davydenko said. "I was thinking, not again, please."
Federer, who clinched the year-end No. 1 ranking after winning his second group match, again didn't look like himself at the O2 Arena, often misplacing his usual dominating forehand and sometimes struggling to hold serve.
Even the fans may have questioned who it was on the court when the scoreboard operator mistakenly put a red-white-and-blue-striped Russian flag next to Federer's name for a portion of the match. It was, however, quickly replaced by the familiar Swiss symbol of a white cross in a red background.
"Sure, it's disappointing. But not to lose against him, just to lose the semis," Federer said. "He finally beat me today. I wish him all the best for the final."
"You can't turn around every single match against top guys because then you don't have enough cushion anymore at the end," said Federer, who won the French Open this year to complete a career Grand Slam. "It's a game of luck at the end."
On Saturday, Federer was stellar in the opening two games, first holding at love with a pair of aces and then earning a pair of break points in the second game. But Davydenko saved them both, and he then went on his streak of breaking Federer three straight times. The 15-time Grand Slam champion broke back once.
"I picked sometimes wrong choice of shots, right from the start," Federer said. "After that, I didn't serve very well in the first set at all."
To start the second set, Federer slowed down his powerful serve, raising his first-serve percentage, and held easily throughout.
However, he still showed his frustration early in the set. After sending backhand return into the base of the net, the ball came bouncing back toward him and he kicked it over to the other side of the court. That, too, went wide.
But leading 5-4 in that second set, he managed to break Davydenko for the second time when the Russian sent a forehand wide on Federer's second break point.
Davydenko came into the match on Saturday afternoon after playing well into the night the day before, when he needed three sets to beat Soderling. He said he didn't get to bed until 3 a.m. and slept for only seven hours ahead of Saturday's match.
"But feeling OK really," the Russian said. "Seven hours was enough."
"I don't think, 'Now I'm No. 1,' because I beat Federer," Davydenko said. "But I know now in confidence, if I beat everyone then I can play very well."
Del Potro dominated with his service game, winning 77 percent of the points on his first serve and 64 percent on his second. He was broken only once, while he broke Soderling twice.
"We played unbelievable points. We served well," Del Potro said. "The difference was just a couple of points in the tiebreak on the second set."
The Argentine lost his opening round-robin match, but has won three straight since then, including a three-set win over Federer on Thursday.
Soderling, who reached the French Open final this year but lost to Federer, said Del Potro did better when it counted.
"Maybe I could have played a little bit better in the important moments and take advantage of my chances," said Soderling, who beat Nadal and Djokovic in his opening two matches. "I don't think I did anything wrong at the end of the match."