Federer gave Switzerland a 1-0 lead in the tie with a 6-4 6-2 win over world number four Alexander Zverev.
But Germany's Angelique Kerber levelled the tie with a 6-4 7-6 (8-6) win over Belinda Bencic in the women's singles rubber.
Switzerland then came up trumps 4-0 1-4 4-3 (5-4) in the deciding mixed doubles that came down to the final point.
Under the short sets format, the match is decided by a winner-takes-all point if scores are locked at 4-4 in the third-set tiebreak.
Germany blew a championship point before it reached that stage, and they again faltered when everything was on the line, with Zverev hitting the ball into the net to spark Switzerland's celebrations.
Federer's three Hopman Cup titles is more than any other player.
The 20-time grand slam champion first won the Hopman Cup in 2001, when he teamed with Martina Hingis to beat the US.
The 37-year-old won his second crown alongside Bencic last year, beating Zverev and Kerber.
