BOSTON -- New York Yankees right-handed starter Sonny Gray has been moved to the bullpen -- maybe for good -- and newly acquired Lance Lynn will take his spot in the rotation.

General manager Brian Cashman said Thursday that Gray's outing Wednesday against last-place Baltimore, in which he allowed seven runs in 2 2/3 innings, forced the team's hand.

"Sonny Gray is a very good major league pitcher and we just haven't had the opportunity to really see that play out over an extended period of time," Cashman said on the Michael Kay Show on 98.7 ESPN New York. "I know that if he winds up somewhere else pitching, he's going to be pitching extremely well, because the equipment is all there, the stuff is all there, (but) consistently it's not playing out right here."

Cashman said Thursday that the Yankees expected more from Gray this season.

"As I said, the more frustrating (aspect) is the fact that he had turned the corner until yesterday," Cashman said. Asked if he tried to move Gray leading up to baseball's trade deadline, Cashman said the offers "weren't good enough" from teams both in and out of playoff contention.

Yankees manager Aaron Boone called the Gray-Lynn switch "the best thing for everyone involved right now," while adding Gray still has the stuff to be a starter and, depending on the situation, might be needed in the rotation down the road.

"Sonny Gray is very close to being a really good starting pitcher -- still," he said. "Even in the starts where he's struggled, he's had moments in those starts, I'm sure if you ask opposing hitters, I'm sure they say, 'Man, this guy's nasty.'

"With our situation, it seems very fluid right now. As injuries pop up, it could change. We very well may need him back in the starting rotation very soon. He may pitch himself back into the starting rotation. Sometimes in baseball a narrative may go one way, but there's countless stories of people kind of resurrecting themselves in the course of a season even."

Gray is 12-15 with a 4.85 ERA since he was acquired from Oakland at the 2017 trade deadline. His season ERA is 5.56 and his ERA at Yankee Stadium is 7.71, currently the highest single-season home ERA for a starting pitcher in franchise history. By comparison, his road ERA is 3.62.

Gray, who learned of the club's decision when he arrived at Fenway Park several hours ahead of Thursday night's Yankees-Red Sox series opener, said he understood the decision and has accepted it.

"I've struggled, and they've given me ample opportunities to turn it around," Gray said. "I'm going to go down there (to the bullpen) and hope to turn things around and get outs whenever my name's called upon. When it gets to this point in the season, it's about winning games, and to this point, today and in the near future, the best thing for this team will be for me to go down there."

Gray, 28, was coming off a strong July, winning three of four decisions and allowing just three runs and nine hits across those outings. He acknowledged, though, that the decline in his on-field performance over time coincided with his arrival to the Bronx.

"I've struggled. I don't know if it has anything to do with New York or if it's just strictly on the field," he said. "It can be a struggle here. It can be a grind. But you can have one moment that can really ... change the narrative."

With New York staring at a 7-1 deficit when Gray was removed Wednesday, Lynn came in for his Yankees debut and threw 4⅓ innings of solid scoreless relief. He allowed just five hits and had five strikeouts.

Before Lynn entered, Gray drew the fans' ire as he flashed a smile while boos echoed throughout Yankee Stadium.

"That's how I handle things. I've done that my whole life," Gray said, referring to his facial expression. "When you get put in a hole like that as a team, as many times as I've done that to us this year, it's a frustrating spot to be in. That's kind of how I handled the situation. It's kind of how I tell myself to move on and not think about it and not let [bad performances] get to you."

Gray said he doesn't see himself pitching out of the bullpen permanently, either in New York or elsewhere.

"I don't think my days as a starting pitcher in this league is over," he said. "Right now, the thought is to have me go to the bullpen and see what happens. Whether it's this year or next year or down the road, I truly envision myself as a starter in this league."