Federer’s 95th ATP tournament win — the eighth in his hometown Basel event where he was once a ballboy — lifted him out of a tie with Ivan Lendl, trailing only Jimmy Connors who has 109.
The top-seeded Federer succeeded on the same court where he lost the 2012 and 2013 Basel finals to del Potro.
Federer rallied from a break down in the decisive set and clinched when the fourth-seeded Argentine sent a service return long.
Trailing in the second set, the 36-year-old Swiss had slammed his racket on the net cord in frustration when wasting a break-point chance.
Federer improved to 7-1 in finals this season. They include his previous event, the Shanghai Masters two weeks ago, and Grand Slam titles at the Australian Open and Wimbledon.
He now has a 18-6 lifetime record against del Potro, who has a 3-2 edge over Federer in finals.
Federer served for the first set with a 5-4 lead — before del Potro immediately broke back — and let a 3-0 lead slip in the tiebreaker.
Del Petro reeled off six straight points in the tiebreaker, including one after a 23-shot exchange, then clinched with his third set point keyed by a strong serve.
Both players had break-point chances early in the second set, and Federer hit his racket on the net cord after spurning his with a backhand volley sent wide.
Federer gifted del Potro a chance to break with two double faults but held with strong serves.
Forcing two set points on del Potro’s serve, Federer took the second when seeing his opponent’s baseline forehand fly long.
They traded service breaks to open the decisive set, and Federer stood head bowed for several seconds with his hands on the net when a wild forehand gifted del Potro his chance.
On the next point, Federer netted a backhand volley to fall behind 1-0, though soon leveled with a fierce forehand winner.
Federer broke again for a 3-1 lead and served out the match under little pressure.