The 30-year-old Swiss, who added a 17th grand slam title to his collection last month on the same Centre Court, survived a record-breaking scrap to win 3-6 7-6 19-17 in the longest men's three-set match played in the professional era.
The third set alone took an astonishing 163 minutes with Federer, who served for the match at 10-9 but was broken to love, claiming victory when his exhausted opponent fired an attempted backhand pass into the net.
Federer won doubles gold in Beijing four years ago with Stanislas Wawrinka but had never previously reached an Olympics singles final.
He will face Britain's Andy Murray, whom he beat to win a seventh Wimbledon singles title, in the final on Sunday.
"It was a big match obviously. Very tough from start to finish. Juan Martin did so well to hang in there," Federer, still looking fresh despite his exertions, said.
"I got lucky in the second set to get back and then in the third it was so tough. I don't think I have ever played as long a set in a best of three-set match.
"Obviously I feel bad and horrible for Juan Martin but he can be very proud. I had a sense though that it was something special and it was cool to be part of a match like that."
"It is tough to speak now, I feel sad, but Roger made a fantastic match, he is a good winner," Del Potro said.
"When you lose you can't see the good things. It hurts a lot to lose like that."
Federer struggled in the first set against the relentless power of Del Potro, who he lost to in the final of the 2009 U.S. Open but has beaten consistently since.
Del Potro dominated the baseline exchanges to take the opening set in 36 minutes and he remained in charge during the opening games of the second set as Federer hung on.
With Argentine fans roaring their man on and cries of "Roger Roger" resounding around the court, Federer upped his game to win the second set tiebreaker.
No one could have imagined what was to follow though.
Serving second, Federer was always playing catch-up but the Swiss remained rock solid on serve, never once offering Del Potro a match point despite standing one game away from defeat on 12 occasions in the final set.
When he broke the Del Potro serve to lead 10-9 it seemed Federer had the match in his hand but the opportunity came and went in a flash as the match extended past the fours three minutes it took Spain's Rafa Nadal to beat Djokovic in the 2009 Madrid Masters semi-final.
At 17-17 Del Potro wavered again on serve to hand Federer a second chance.
Federer fluffed an easy volley on his first match point but kept the pressure on and roared his relief when Del Potro netted to finish the match.