Federer, this year's Australian Open and Wimbledon champion, won 4-6, 7-6 (8/6), 11/9 to give Team Europe an unbeatable 15-9 lead.
But the 36-year-old Swiss legend struggled against the 20th-ranked, 22-year-old Australian and his flawless serve, losing the first set on a single break.
When he finally broke Kyrgios halfway through set two, he yelled "Come on!" in relief, only to lose his serve again in the next game.
But Federer capitalised on the system of the tournament he had founded -- forcing Kyrgios into longer exchanges, he edged him in the second-set tie-break, then came back from 8-5 down in the decisive super tie-break.
"I kind of felt good going into the breaker," Federer said. "It was a nail-biter at the end but for me personally it was a dream scenario.”
Federer then praised the tournament. "It was an incredible journey really, it was way better than I ever thought it would be. It felt like winning some of the biggest matches in my life. It was like a fairy tale.”
Kyrgios said the loss "just hurt. I gave everything I had and I came short."
Team Europe, the odds-on favourites with five of the world's top seven players, entered Sunday with a 9-3 lead which narrowed as Jack Sock and John Isner beat Tomas Berdych and Marin Cilic in the opening doubles rubber.
On Sunday, the winner of each rubber earned three points, against one on Friday and two on Saturday.
Alexander Zverev then took Europe within sight of the trophy by beating Sam Querrey in straight sets, but world number one Rafael Nadal missed his chance as he lost to big-serving John Isner in straight sets.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ