Argentina 24th seed Del Potro claimed a heroic 1-6, 2 -6, 6-1, 7-6 (7/1), 6-4 victory over the sixth-seeded Austrian on a rocking Grandstand court, describing it as night he would remember forever.
Del Potro famously defeated Federer in the 2009 final for his only career Grand Slam title before his career was almost torpedoed by a succession of wrist surgeries.
Federer, the third seed, eased into the last-eight with a 6-4, 6-2, 7-5 win over Philipp Kohlschreiber, taking his record over the German veteran to 12-0.
In the women's event, world number one Karolina Pliskova set-up a quarter-final date against America's CoCo Vandeweghe.
More From This Section
Estonia's world number 418 Kaia Kanepi also reached the quarter-finals, just the second qualifier to make the last eight.
But the day belonged to Del Potro, who celebrated his win, which came off a Thiem double fault, by stretching out his arms, head facing the night sky, as his legion of fans, many dressed in the light blue colors of Argentina's famed football and Pumas rugby teams, celebrated wildly.
"I was sick the last two days. I came here trying to play the best I can and then when I see this crowd cheering for me, I was trying to play better every game. I will always remember this."
- Federer's 'bum' note -
========================
Federer has a 16-5 advantage over Del Potro but they have split their last six meetings.
The 36-year-old Swiss maestro didn't face a break point against Kohlschreiber with his biggest challenge having to take a medical time-out off court at the end of the second set.
"It's great to see him back on tour. He's had a rough ride with wrist problems. He's a good guy."
World number one and 2010 and 2013 champion Nadal, who could meet Federer for the first time in New York in the semi-finals, crushed Ukraine's Alexander Dolgopolov 6-2, 6-4, 6-1.
The 31-year-old Spaniard goes on to face Russian 19- year-old Rublev, who stunned Belgian ninth seed David Goffin 7-5, 7-6 (7/5), 6-3 to become the youngest quarter-finalist since Andy Roddick in 2001.
Rublev, ranked 53, has won 13 of his last 17 matches after breaking the top 100 for the first time in June.
"Rafa is a real champion. I will try to do my best -- I have nothing to lose," said Rublev.
Meanwhile, the 32-year-old Kanepi, a former world number 15 whose career was almost ended by illness and a crippling injury, downed Russia's Daria Kasatkina 6-4, 6-4.
She will next face Madison Keys of the United States, who put out fourth seed Elina Svitolina 7-6 (7/2), 1-6, 6-4, ending the Ukrainian's hopes of taking the world number one spot.
"It's very tough to believe where I am now after all that has happened. I didn't expect it," said Kanepi, who is playing in the main draw of an event for the first time this year.
Top seed Pliskova, the runner-up in 2016, needed just 46 minutes to sweep past American Jennifer Brady 6-1, 6-0 and make her third Slam quarter-final of the year.
She will next face American 20th seed CoCo Vandeweghe, who made the last eight for the first time by beating Lucie Safarova of the Czech Republic 6-4, 7-6 (7/2).