"I knew that if I lose today it's the end of the season, so I gave everything I had and couldn't be more happy," Federer said on court after the match.

The ATP finals is the last tournament of the season, and Federer will face Djokovic in the final match on Monday at the O2 Arena.

"For me, I think for both of us, it's pretty straightforward," said Federer, who is 16-12 against Djokovic. "I think we've got to press out the last juice that's left in our body and make it a successful year end, even though it's been successful for everybody who has been taking part in this tournament."

Federer found himself in a hole early against Murray, losing his serve in the opening game of the match. But Murray, who lost to Federer in the Wimbledon final but beat him in the Olympic final, couldn't hang on. The 17-time Grand Slam champion broke back to even the score at 4-4, and then recovered from a 3-1 deficit in the tiebreaker to win the opening set and take control of the match.

"Basically I really tried to pull myself together in this breaker today, where I thought I didn't play great in yesterday's tiebreaker first set against Del Potro, and not being able to come back," Federer said. "Margins are small, best-of-three sets."

In the second set, Federer lost only two points on serve and broke Murray twice.

"Once he gets ahead, he's incredibly hard to stop," said Murray, who leads Federer 10-9 in head-to-head play. "He tends to play better and better when he gets up. I feel like I gave him that advantage the beginning of the second set."

Throughout the match, the packed crowd at the O2 Arena cheered loudly between points. But despite being a hometown crowd for Murray, there were plenty of hoots and hollers for Federer both from the Swiss contingent and others.

That's something Federer has gotten used to over the years.

"I guess because I've been in the game for so long, I do have many people who just enjoy watching me play or feel like it's a throwback maybe to the back-in-the-day times when they used to play with one-handed backhands, and they like me because of those things," Federer said. "I don't know what it is, but I do get a lot of support and do appreciate it."

In the early match, the top-ranked Djokovic started playing his best tennis as soon as it looked like he was headed for his off-season vacation.

Djokovic was broken late in the first set and again early in the second, but he then found his stroke and quickly rebounded.

"Well, I had a little, let's say, crisis in today's match from 4-all, first set to 2-all in the second, where I didn't feel so good on the court, struggling to find my momentum and my rhythm," Djokovic said. "So you try to be positive and push myself to fight for every point and believe I can come back. That was the case."

Del Potro took the lead late in the first set, breaking Djokovic for a 5-4 lead before serving out the set at love.

The tall Argentine, who defeated Djokovic to win the Olympic bronze medal at Wimbledon this year, then went up a break early in the second set. But Djokovic broke right back to 2-2 and then took Del Potro's serve again to take a 5-3 lead.

"He's so good," Del Potro said. "Of course, he's the No. 1. In these kinds of matches, they make the difference between them and the rest of the players."

In the third, Djokovic decided things by winning 12 of 13 points in a three-game stretch to take a 3-1 lead. He broke again three games later and held at love to advance.

"I believed that I could come back," said Djokovic, who treated the media to chocolates during his post-match news conference to thank them for work throughout the year. "I believed that I could turn this match around in my favour, and I've done so."

The victory was Djokovic's 74th of the season, tying him with David Ferrer for the most this year. It was also his seventh win in nine matches against Del Potro.

Djokovic won the ATP finals in 2008, and reached the semifinals in 2009 — the first year the tournament was played at the O2 Arena in London.