Federer has never lost in the first round in New York but a shock looked on the cards after Tiafoe took the opening set but Federer looked as though he had regained full control after winning the next two.
However, Tiafoe kept on plugging away at the 19-time Grand Slam winner and the teenager proved why he is one of the brightest young stars in tennis with a brilliant display in the fourth.
And the fifth set could have gone either way with Federer uncharacteristically giving up more than 50 unforced errors throughout the whole match with Tiafoe capitalising on his opponent.
The Swiss tennis star missed the chance to win the match at the first time of asking in the fifth set when he dropped a backhand volley into the net.
Tiafoe would go onto break Federer’s serve to the delight of the Flushing Meadow’s crowd.
But Federer would go on to have two more match points on Tiafoe’s serve, the second of which resulted in the 36-year-old progressing to the second round.
And Federer was full of praise for his opponent for pushing him all the way and almost causing a huge upset.
“It was more than a test, it was a good one,” Federer said.
“I think we both enjoyed ourselves out here tonight and you guys [the crowd] made it very special for us to keep fighting so I’m very happy with the match.
“I had a bit of a slow start but Frances also fet good from the beginning.
“I was maybe a bit worried about my back issue from a couple of weeks ago but eventually I was able to let go.
“The fourth set was maybe a pity that I couldn’t get in the driver’s seat early but Frances fought well.
“He started to serve better in patches and when things connect for him he’s a very good player and he’s going to have a great future.
“In the fifth it’s a toin coss. It went my way tonight so I’m very happy.”