ST. PETERSBURG, Florida — Ryan O’Hearn didn’t have a spot on the team out of spring training.

Now the team can hardly afford to leave him out of the lineup for even one day.

O’Hearn, playing the best baseball of his career and having the most fun he’s ever had doing so, was key for the Orioles in a pivotal series against the Rays. On Saturday, his pinch hit drove in the winning run.

And on Sunday O’Hearn did it again. His homer in the sixth — a 331-foot squeaker that would have made it over the wall in just two of 30 stadiums — was the go-ahead run in the Orioles’ 5-3 win over the Rays.

The Baltimore Banner thanks its sponsors. Become one.

“I’m definitely enjoying the big hits and contributing,” O’Hearn said, adding later, “Two really good teams going at it, it was a grinder, every game. They have a really good team over there, but so do we. Every pitch matters; every inning matters, every hit.”

Baltimore took three out of four in the series, moving two games ahead of Tampa Bay in the American League East. It was only the second time the Orioles have won a four-game series in Tampa Bay, the other coming April 10-13, 2006.

The teams will play once more this season, with the Rays needing to sweep the four-game set at Camden Yards in September to win the season series, which may be crucial later. If the teams have the same record at the end of the season, and no one else surpasses them, the division will go to the one with the better head-to-head record.

That means not only a first-round bye but likely home-field advantage throughout the postseason.

“For some of the guys like myself who don’t have playoff experience, it felt like a playoff game,” shortstop Gunnar Henderson said. “Getting a sense of what it will feel like will help us down the road.”

The Baltimore Banner thanks its sponsors. Become one.

O’Hearn’s heroics highlight the strategic way the Orioles have built what will likely be their first playoff team since 2016. They have the top draft picks from their rebuild years, Adley Rutschman and Henderson, both fixtures in the lineup every day.

But they also have found a knack for spotting underrated talent like O’Hearn. He was traded from the Royals for cash considerations, then designated for assignment and reassigned to Triple-A to begin the season.

Recalled in April, he played a pivotal part with Ryan Mountcastle out with vertigo, making himself so valuable the team had no choice but to keep him after Mountcastle returned. Now, O’Hearn’s .881 OPS leads the team.

“I’ve been feeling confident,” he said. “Definitely the way things are going right now is awesome. ... As soon as you start patting yourself on the back too many things can go south, so just trying to stay focused on the process.”

The Orioles had a steady lead prior to the fifth inning, the team getting one run in the first and two in the second off an RBI double from Rutschman and a home run from Henderson.

The Baltimore Banner thanks its sponsors. Become one.

But the Rays, as they typically do, came back against Tyler Wells. Tampa Bay scored its first run before recording a hit, Wells walking the first two batters of the fourth and the runner scoring on a fielder’s choice. The Rays eventually got a hit in the fifth — a two-run home run by Yandy Diaz — to tie the game.

Wells’ day ended a batter later. He walked a career-high four and hit two as command issues led him astray.

“I didn’t have a good rhythm,” Wells said. “I felt like I put in a lot of good work in between last start and this start. You know out there today it didn’t quite translate. Walks, the hit batters, not what you want. Ultimately I paid for it. Very frustrating to say the least, but I’m not going to look at the negatives too much.”

O’Hearn’s home run in the sixth gave the Orioles the lead back, and they added one more in the seventh off an RBI single from Anthony Santander. Yennier Cano and Félix Bautista wrapped up the win.