Federer, 34, ended a five-match losing streak against Nadal to win 6-3 5-7 6-3 in just over two hours, in their first meeting at his home ATP event in Basel.
It was the 17-time Grand Slam winner's sixth title of the season and the 88th of his career.
Third seed Nadal, 29, still has a 23-11 head-to-head record against world number three Federer.
With the match finely poised in the deciding set, Federer fired a series of winning ground strokes and broke Nadal's service for a decisive 5-3 lead.
The match was the first between Federer and Nadal since the Spaniard won their Australian Open semi-final in straight sets in January 2014.
Earlier, Britain's Jamie Murray and Australian partner John Peers were defeated in the men's doubles final, losing 7-5 7-5 to Alexander Peya of Austria and Brazil's Bruno Soares.
Top seed Roger Federer beat his old rival Rafael Nadal in three sets to claim his seventh Swiss Indoors title.