It was a good run while it lasted, full of tension and excitement in equal measures, but Maria Sharapova’s comeback to the U.S. Open ended on Sunday in the fourth round.

That’s where Anastasija Sevastova put the brakes on Sharapova’s powerful game, rallying for a 5-7, 6-4, 6-2 win at Arthur Ashe Stadium in a match that seemed almost anticlimactic, given the whirl around Sharapova’s return to Flushing Meadows.

The Open had been the first real test of Sharapova’s game since she returned from a 15-month drug suspension in April. She had played only nine matches coming into this Open, hampered by a thigh and left arm injury that forced her to forgo Wimbledon qualifying and most of the American hard court season.

“It’s been a really great ride in the last week,” Sharapova said Sunday night. “Obviously coming off a loss, you know, it’s a quick turnaround in order to reflect all the positives that happened in the last eight or nine days. But ultimately I can take a lot from this week. I’m very thankful for the opportunity. I did my best. I can be proud of that.”

The 2006 Open champion, who needed a wild card to get into this year’s tournament, defeated No. 2 seed Simona Halep in the first round in a gritty, dramatic match on Ashe. She had played all four of her matches on Ashe, her appeal remaining strong to Open officials and the television producers.

She hadn’t played at the Open since 2014, missing 2015 with an injury and last year because of the drug ban. It was also her first Grand Slam since Australia in January 2016, which was shortly after her ban for the drug meldonium was announced.

After beating Halep, she backed it up with wins over Timea Babos and American Sofia Kenin.

advertisement | advertise on newsday

“Monday night was a special night for me,” Sharapova said. “I will always remember it. I’m very grateful to have had that opportunity to bring it.”

There was no dramatic turnaround Sunday, no big point or game that turned the match toward Sevastova, who reached the quarterfinals here last year before losing to Caroline Wozniacki. Sharapova is always going to make errors, hitting out aggressively, going for winners. It’s just a case of making the math work. Sunday, it didn’t. She made 51 errors to 42 winners.

Sevastova, who after getting her timing down on Sharapova’s powerful ground strokes, made only 14 errors and was particularly effective with her slices and drop shots, yo-yoing Sharapova first to the net, then forcing her to retreat toward the baseline.

Still, it didn’t seem so drastic that Sevastova, enjoying one of her best seasons by reaching a career best ranking of 16 after Wimbledon, had taken the second set after losing the first on a break of her serve.

Then Sharapova played a poor service game to open the third set, double faulting to hand Sevastova the first game — and some momentum. Sevastova held her service on four points, then put the hammer down on Sharapova’s serve in the third game. She played a deft drop-shot winner, Sharapova made an error on her own drop-shot attempt and erred on a backhand to give Sevastova a second break of serve. Sharapova got one break back in the fourth, but that was it.

@NewsdaySports

Sevastova’s complex game was by design. “Mixing up, slice. I couldn’t hit her off the court, that’s for sure, so I had to have a game plan,” Sevastova said. “I had to play a lot of slice, mixing it up, forehand running, so that she moves to her forehand.”

Sharapova intends to keep going at age 30, something she once thought couldn’t happen.

“I love the feeling of playing tennis. I mean, as a woman, it’s a very powerful feeling to feel like you’re great at what I do and can be even better and improve,” she said. “I was given a gift when I was a young girl, and with the help of a lot of people, a lot of different paths, yeah, I have the ability to keep doing that.”