In the biggest mixed doubles drawcard in the 31-year history of the tournament, in what is expected to be its final edition, Federer teamed with Belinda Bencic to win the match in straight sets under the Fast4 format and win the Group B tie for Switzerland.
With 43 Grand Slam singles titles (Williams 23, Federer 20) and more than US$200 million in prize money between them, the two 37-year-olds had welcomed the chance to face each other on the court in an official match for the first time.
As it turned out, the tie was decided by the mixed doubles, after both Federer and Williams won their earlier singles matches.
A capacity crowd of 14,064 turned out for the tie, and they saw Federer and Bencic largely capitalise on the mixed doubles inexperience of Williams' teammate, Francis Tiafoe, to clinch the deciding rubber under the Fast4 format, 4-2, 4-3 (5/3).
Williams, who seemed to be troubled by her right shoulder during the match but said it wasn't a concern, was disappointed her doubles experience didn't give the Americans the edge.
However, even a rare defeat couldn't take the gloss off the experience of facing Federer for the first, and almost certainly the only, time.
“I was so excited and literally it was the match of my career,” she said.
“Playing someone so great and that you admire so much in a match that actually means something.
“It is really great and special to go against the greatest of all time.”
Federer said he was thrilled to play against one of the few players with more Grand Slam titles.
“I really enjoyed playing against Serena, what an honour and pleasure,” he said.
“I was nervous returning because people talk about her serve so much.
“It was great fun, she is a great champion, you see how focused and determined she is and I love that about her.”
The pair posed together for a selfie after the match.
'Great start to season'
In his singles match, Federer scored successive wins to start the new season with an impressive 6-4, 6-1 victory over Frances Tiafoe.
The world number three was challenged early by the 39th-ranked American, but then secured the first set with a break in the 10th game.
Federer won seven games in succession and eight of the last nine as Tiafoe dropped away.
It was another encouraging performance from Federer as he builds his preparation for the upcoming Australian Open in Melbourne, where he will be looking to win a third successive title and seventh overall.
“It's been a great start to the season for me, I found a way and I have to be happy right now,” Federer said.
“It's about staying fit and healthy and managing the game day by day.”
Williams raced to an early 3-0 lead against Bencic, but then lost her way as the Swiss number 54 gained successive breaks of serve to secure the first set.
Although the American was hitting more winners, she was also making more errors and looked in trouble until she broke Bencic in the 10th game to take the set and level the match.
An early break in the final set to Williams was crucial as she used her big serve to hold Bencic at bay and win 4-6, 6-4, 6-3.
“It was definitely a relief,” Williams said of the result.
“She played really well but I knew I could play better.”
If Switzerland beats Greece on Thursday they will be through to the final, where they will defend the title they won last year.