Latvia's Sevastova, the 16th seed, won 5-7 6-4 6-2 to reach the quarter-finals in New York.
The 27-year-old will play Sloane Stephens in the quarter-finals, after the American beat Julia Goerges, reports BBC.
Sharapova, ranked 146th after returning from a doping ban in April, was given a wildcard into the main draw.
"It's been a really great ride in the last week," said the 30-year-old.
"I can take a lot from this week. It's great to get that major out of the way. It was an incredible opportunity. I'm very thankful for the opportunity.
"I did my best. I can be proud of that."
The 2006 champion had played just one match since May coming into Flushing Meadows, with injuries forcing her out of the grass-court season and US Open build-up.
She played superbly to upset world number two Simona Halep on the first day of the tournament, and then beat Timea Babos and Sofia Kenin on her way to the last 16.