The 22-year-old Pole had not dropped a set on her way to the fourth round, but she had never beaten Ostapenko in three previous career meetings.
Swiatek took the first set with relative ease but then Ostapenko's sledgehammer of a forehand started finding its mark to level the match.
A one-sided final set saw former French Open champion Ostapenko triumph 3-6 6-3 6-1. Swiatek's defeat means that Aryna Sabalenka of Belarus will take over as world No1 after the tournament.
Ostapenko will face Coco Gauff in the quarter-finals after the teenager ended the Grand Slam comeback of mother-of-two Caroline Wozniacki.
The 19-year-old came from a break down in the first and third sets to win both and complete a 6-3 3-6 6-1 victory.
Wozniacki's return has been one of the stories of New York this year, having come out of retirement after more than three years and two children later.
The 33-year-old former world number one has looked as though she has never been away, but a fired-up Gauff proved just too strong in the deciding set.
Wozniacki got off to a dream start with a break in the first game and a 2-0 lead. But Gauff quickly got back on the board, levelling at 3-3 before going on to clinch the first set without dropping another game.
Wozniacki cranked up the pressure in the second and Gauff started feeling it as her suspect forehand began to misfire and she was broken for 5-3 as the Dane levelled the match.
Gauff looked uncomfortable as she dropped serve again at the start of the decider, but after pointedly ignoring the advice of coach Brad Gilbert, the wound-up American began firing backhand winners as if they were going out of fashion.
She reeled off the next six games to clinch the victory and let out a loud scream of triumph after converting match point.
"Definitely getting it to 2-1 (in the third set) was the turning point," said Gauff. "I got broke and I showed I was still in the match. I started to go for my shots.
"Caroline, it's like she's never left, the level she played was amazing. It's weird because I grew up watching Caroline and when she won the Australian Open, so to be on court with her today was an honour.
"She definitely gets to a lot of balls. I felt a bit like I was playing myself. I knew I had to play aggressive and go for my shots. In some moments I miss but I was happy I could get back and refocus."
It will be the fifth Grand Slam quarter-final of Gauff's still-fledgling career and her second at Flushing Meadows.
"I've been in this position before," she added. "And I think I have confidence in myself that I can go even further."