NEW YORK — The Orioles were hoping Colton Cowser’s energy and spunky personality — in addition to his sharp playing skills — would provide a spark for a team vying to get back on the right track.

Their intuition was right.

Cowser’s first MLB hit got the Orioles on the board Wednesday night and started a four-run rally. They went on to beat the Yankees 6-3, just their second win in their last eight games.

This hasn’t been an easy stretch for the Orioles, but the players have tried to remain calm, reminding themselves that their hot start means they can afford to have a few rough patches. They are still, after all, in playoff position with four games until the All-Star break.

The Baltimore Banner thanks its sponsors. Become one.

“Last year we weren’t given this type of luxury, so a four to five game skid felt a whole lot weightier,” Kyle Gibson said. “We understand that we put ourselves in a really good spot right now we can weather storms like this. ... A nice short stretch can turn it around pretty quickly.”

Perhaps Wednesday was the beginning of that.

Dean Kremer, coming off his worst start of the season, turned out one of his best performances. On June 30, Kremer allowed seven runs in three innings. This time around, he gave up just two runs and struck out a career-high 10 batters in seven innings, tied for his longest outing of the season.

“I think I had everything working,” Kremer said. “Adley and the team had a pretty good approach to what we wanted to execute tonight.”

Kremer cruised through his first four innings, giving up just one hit. In the fifth, Josh Donaldson hit a home run to give the Yankees a 1-0 lead.

The Baltimore Banner thanks its sponsors. Become one.

The game paused briefly after that, as an errant throw from Gunnar Henderson struck MASN camera operator Pete Stendel in the first base well. Stendel was carted off the field, but raised a hand up as he exited with paramedics.

“I hope he’s doing alright,” Henderson said. “My prayers go out to him and I’m just thankful for the guys who rushed over.”

When the game resumed, the Yankees were able to tack on one more run, but that would be all Kremer would allow.

The Orioles offense arrived in the sixth, providing some needed support to their starter. Cedric Mullins, batting just .143 since he came back from the injured list, hit a double to open the inning. Aaron Hicks, to more resounding boos, provided a single, setting up runners on both corners for Cowser.

Cowser delivered, sending a single to right field as Mullins scored. Cowser’s best friend Jordan Westburg — who helped make Cowser’s transition to the big leagues seamless — followed with a RBI triple to send two more runs in.

The Baltimore Banner thanks its sponsors. Become one.

“That was awesome, I wish he would have a split the gap a little more so I wouldn’t have to stop,” Cowser joked. “I’m just glad he’s here with me.”

Adam Frazier wrapped up the scoring spree, reaching on a fielder’s choice as Westburg scored.

The Orioles added two more runs in the ninth after Adley Rutschman doubled and Ryan O’Hearn homered. Félix Bautista got the four-out save.