For most of Saturday's Group B shootout for the right to play Rafa Nadal, the 17-times grand slam champion looked to be heading for the exit but the Swiss refused to buckle under the Argentine's brutal power and clawed out a 4-6 7-6(2) 7-5 win.
It has not been a vintage season for Federer, who has dropped to world number seven, but he could yet end it on a high, although he must get past world number one Nadal who won Group A with a 100 percent record.
Federer's enthralling victory over del Potro sealed runners-up spot in Group B behind Novak Djokovic who will face Federer's fellow Swiss Stanislas Wawrinka in the other semi.
Before that Djokovic faces Richard Gasquet in a dead rubber later on Saturday.
It was a display of wild fluctuations from Federer against an opponent to whom he had lost three times in a row before a confidence-boosting victory at last week's Paris Masters.
He admitted he had been a little fortunate to survive.
"A lot of coming from behind, trying to get back into the match, and it was amazing that I was able to pull it off," a delighted Federer said on court.
"I could never play free-flowing tennis. I fought hard, maybe got a bit lucky at times."
EXHILARATING COMEBACK
The 32-year-old Swiss seemed to sacrifice substance for style as he casually lost serve twice to trail 5-1 in the opening set before he almost repaired the damage with an exhilarating comeback that fell just short when del Potro aced his way out of trouble when serving at 5-4.
Six-times former champion Federer had only once fallen in the round-robin phase of the season-ending event in 11 previous appearances and never since it switched to London in 2009.
He found himself a break down in the second set too but reeled off 12 consecutive points as the pendulum swung his way and then played a majestic tiebreak to level.
Federer dipped again at the start of the deciding set when a netted forehand gave del Potro a 2-0 lead.
Again Federer responded to a deficit with some of his most forceful tennis and del Potro's erratic forehand gifted the break back in the fifth game.
The sell-out crowd roared their approval at 4-4 when del Potro produced an incredible lob played between his legs and Federer replied with a smash over his shoulder before finishing the point with a whipped forehand winner.
Del Potro responded to hold but with Swiss cowbells echoing around the arena, Federer held his nerve to make it 5-5 and then pounced to gain the decisive break for 6-5.
Even then del Potro looked like forcing a deciding set tiebreak but Federer would not be denied and belted down his 10th ace to complete a remarkable victory.
"I don't get a day off, I've got to back it up and be ready to go again tomorrow," Federer said.
"I'll try to make his (Nadal's) life a bit difficult."
(Reporting by Martyn Herman, editing by Tony Goodson)
Share
