The St. Louis Cardinals have agreed to a three-year deal with free agent pitcher Sonny Gray, the team announced on Monday.

Gray, 34, joins a revamped Cardinals rotation that also includes recent free agent additions Lance Lynn and Kyle Gibson.

“We were hoping to sign a couple of pitchers we knew we could count on for innings,” John Mozeliak, the Cardinals’ president of baseball operations, said during a news conference Monday. “And if we could accomplish that, we were hoping we could do something a little bigger, a little longer, and obviously that’s where Sonny fits in.”

Gray is coming off a strong 2023 season with the Minnesota Twins. He finished second in AL Cy Young Award voting behind Yankees right-hander Gerrit Cole and earned his third career All Star Game appearance.

The veteran right-hander made 32 starts, going 8-8 with a 2.79 ERA, striking out 183 batters over 184 innings.

Over 11 seasons with the A’s, Yankees, Reds and Twins, Gray is 98-85 with a 3.47 ERA.

“Where I am in my career,” Gray said, “I want to win. I’m coming to an organization like St. Louis — the tradition, just walking in here this morning, walking around seeing everything — the history is there. The feel is there. It’s just a baseball town and city and a place that I’m thrilled to be able to come and be part of it.”

The Cardinals entered the winter seeking three starting pitchers to fill out a beleaguered rotation whose 5.08 ERA was the fifth worst in baseball. Gray joins a new-look rotation with holdovers Miles Mikolas and Steven Matz along with Lynn and Gibson. The Cardinals also have young left-handers Matthew Liberatore, Zack Thompson and Drew Rom who all started games to varying degrees of effectiveness last season.

St. Louis ranked 26th in starters’ ERA last season and wasn’t shy about the need to add to its rotation after trading Jack Flaherty and Jordan Montgomery during the season, combined with the retirement of Adam Wainwright.

St. Louis’ poor pitching led to the team’s worst full season (71-91) since 1990.

The Associated Press contributed to this story.