Williams, the tournament's No. 8 seed, rolled her ankle midway through the second set, but managed to close out the 6-3, 6-4 win in one hour, 32 minutes at USTA Billie Jean King National Tennis Center in Flushing, N.Y.
Williams received treatment from a trainer, who added tape to her lower right leg and foot during a medical timeout. She recovered quickly from the ailment to reach the quarterfinals at Flushing Meadows for the 11th consecutive time.
"I just rolled it. I don't know why," Williams said in her on-court interview after the match. "I was volleying and it just went over. That was a little frustrating, but I just wanted to get it compressed really fast and that's what I did."
Williams will play No. 18 Wang Qiang, who upset second-seeded Ashleigh Barty in straight sets Sunday, in the quarterfinals. She is seeking her 24th career Grand Slam title and first tournament win since stepping away from tennis in 2017 for the birth of her daughter.
In other women's action, No. 16 Johanna Konta upset third-seeded Karolina Pliskova in their fourth-round match.
Konta rallied to defeat Pliskova 6-7 (1), 6-3, 7-5. She became the first British woman to reach the U.S. Open quarterfinals since Jo Durie in 1983.
Konta's victory over Pliskova marks her third appearance in the quarterfinals of a Grand Slam this season and the fifth in her career. She will take on either No. 5 seed Elina Svitolina or Madison Keys in the next round.
Federer defeated Goffin 6-2, 6-2, 6-0 in the fourth round. After sluggish starts in the opening two rounds, he has lost only nine games over his last two matches.
The 20-time Grand Slam champion will face Grigor Dimitrov, who knocked off Alex de Minaur in straight sets Sunday, in the quarterfinals.