The 17-time Grand Slam champion beat France's Gasquet 6-4 6-2 6-2 to give the Swiss an unassailable 3-1 lead.
"This one is for the boys," said Federer, who was in tears at the end of the match.
"This is not for me, I have won enough. I am just happy we can give everyone in our country a historic moment."
Federer, 33, also paid tribute to compatriot Stan Wawrinka, who helped set up the victory in Lille by beating Jo-Wilfried Tsonga before partnering Federer to win the doubles.
Federer and Wawrinka were involved in a row at the ATP Tour Finals in London, which the world number two later described as "heat of the moment".
"Stan has put in so much effort over the years. He played an unbelievable weekend and that is what gave me the opportunity today," said Federer.
Federer, who lost his singles rubber to Gael Monfils on Friday, played an inspired match as he crushed Gasquet, who replaced Tsonga due to an arm injury.
In front of a passionate crowd of 27,448 - a world record for a competitive tennis match - Federer dropped only four points on his imperious serve in the opening set, which he sealed with a whipping forehand winner.
World number 26 Gasquet dropped serve in the first and seventh games of the second set, which Federer took without conceding a single break point.
He broke the Frenchman twice in the final set to serve for the match and claimed victory with a deft backhand drop shot - collapsing in tears onto the clay at the Stade Pierre-Mauroyto.
The Swiss win comes a week after Federer pulled out of the Tour Finals title match against Novak Djokovic at the O2 in London to protect a back injury.

"In full co-ordination with the government of Iraq, we're deploying a specialised expeditionary targeting force to assist Iraqi and Kurdish Peshmerga forces," Mr Carter said.
The operators would carry out raids, free hostages and capture IS leaders.
They would also conduct "unilateral operations" in Syria, he said.
Islamic State conquered large swathes of Iraq and Syria in the summer of 2014.
A US-led coalition of 65 countries is conducting a campaign against the militants in both countries.
Mr Carter made the announcement in remarks to the House Armed Services Committee in Washington on Tuesday.
He did not offer specifics on troop numbers, but said they would also be focused on securing Iraq's borders and building the capacity of the Iraqi government forces.
US special forces have already conducted operations in both Syria and Iraq - notably the killing of the IS oil chief Abu Sayaff in eastern Syria and the freeing of prisoners from the IS-held town of Hawija near Kirkuk in Iraq.
But this is a clear indication from the Pentagon that their role will become more significant.
The "specialised expeditionary targeting force", as the Iraq group is being called, will not only assist local forces but will also conduct further "unilateral" raids into Syria.
While this does not amount to significant numbers of boots on the ground, it is an escalation of America's role in direct combat.
Mr Carter said there was now an important opportunity to divide IS militants in Iraq from those in Syria.
In October, the US announced it would send up to 50 special forces soldiers to northern Syria as military advisers to Kurdish and rebel forces.
Roger Federer beat Richard Gasquet to seal Switzerland's first Davis Cup triumph, then dedicated the victory to his team-mates.
[NEXT_CONCEPT]
The US is to deploy a specialised force to Iraq to build pressure on Islamic State militants, US Defence Secretary Ashton Carter has said.