The big-hitting Argentinian, who was beaten in the London 2012 Olympics semi-finals by Federer, secured revenge to beat the world number one 6-4 6-7 (7/5) 7-6 (7/3).
Federer was chasing his sixth Swiss Indoors title and his third tournament victory in a row, but Del Potro took the first set to give him confidence after losing his previous six meetings with Federer this year.
The 31-year-old Federer was competing in his ninth Swiss Indoors final and hit back in the second set to set up a decider.
The third set, like the second, went all the way to a tie-break as both players took the strain of a match that lasted two hours and 44 minutes.
But it was Del Potro who secured his second successive title, having also won in Vienna last week.
Watch: Del Potro beats Federer, wins Swiss title... More Videos