Roger Federer has overcome a back injury in time to help Switzerland capture a first Davis Cup trophy.