Ryan McMahon of the Colorado Rockies follows the flight of...

Ryan McMahon of the Colorado Rockies follows the flight of his three-run home run against the St. Louis Cardinals at Coors Field. Credit: Getty Images/Dustin Bradford

It is no secret that third base has been a position of weakness for the Yankees this season.

But six days before the trade deadline, they acquired a smooth-fielding, hard-hitting player from the worst team in the majors.

On Friday afternoon — before the Yankees fell to the Phillies, 12-5, at the Stadium — the club announced that it had traded for Rockies third baseman Ryan McMahon.

The Yankees sent two 22-year-old minor-league pitchers — lefthander Griffin Herring and righthander Josh Grosz — to Colorado. According to MLB Pipeline, Herring was ranked as the Yankees’ eighth-best prospect and Grosz was their 21st.

“Really excited,” Aaron Boone said. “Ryan has been an All-Star third baseman, really good defender. He has had some ups and downs offensively this year. But I know over the last month, he’s really swinging the bat well. He’s a presence and can really defend over there at third, and has for a number of years.”

Boone had not talked to McMahon as of Friday afternoon and said he wasn’t sure when the third baseman will join the team. The Rockies currently are in Baltimore.

Before Friday’s deal was made, the Yankees were rumored to be in the mix for Arizona third baseman Eugenio Suarez, 34, who has 36 homers and likely will command a significant package for the D-backs if traded. Suarez is scheduled to be a free agent after the season.

The lefty-swinging McMahon, 30, has a .217/.314/.403 slash line, 16 homers and 35 RBIs in 100 games this season. Yankees third basemen have posted a .645 OPS this year, the club’s worst at any position.

McMahon has a .241/.316/.504 slash line with 10 homers in his last 39 games. That raised his numbers from .202/.313/.338 on June 6 to his current figures.

McMahon is in the fourth year of a six-year, $70 million contract he signed with Colorado in March 2022. The Yankees reportedly are paying his remaining salary: approximately $4.2 million this season and $16 million in both 2026 and 2027.

McMahon, who has spent all nine of his major-league seasons with the Rockies, was an All-Star last year. He has five 20-homer seasons and is on pace for a sixth this year. His average exit velocity of 94 mph ranks in the 98th percentile.

“I love watching him play, the times I’ve played against him and been on the other side of the field,” Yankees hitting coach James Rowson told Newsday on Friday. “I mean, you look at the skill set, you look at the player, and he’s an exciting guy to watch.”

McMahon goes from the historically bad Rockies (27-76) to a team with World Series aspirations. He’ll look to spark the reigning AL champions, who fell 5 1⁄2 games behind AL East-leading Toronto, which beat the Tigers, 6-2, in Detroit.

McMahon’s home and road splits provide some cause for concern. He had a .248/.365/.491 slash line with 11 homers in 50 games at hitter-friendly Coors Field. In 50 road games, he had a .189/.265/.324 slash line with five homers.

Swing-and-miss also has been an issue for McMahon, whose 127 strikeouts are the second-most in the majors behind Detroit’s Riley Greene (136). His 12.2% walk rate, however, ranks in the 86th percentile.

McMahon, who also has 203 career starts at second base, was a Gold Glove finalist at third each of the previous four seasons. He has 54 defensive runs saved and 42 outs above average since 2021, respectively ranking second and tied for second among third basemen.

Said Boone: “Just the handful of times that we’ve played against him, I watch him and you’re like, that’s what we should look like over there.”

Who will become the odd man out with the addition of McMahon?

It’ll be Jorbit Vivas, who was optioned to Triple-A Scranton after Friday night’s loss.

Oswald Peraza, who has appeared in 17 games at second and eight at shortstop, likely will fill in around the infield.

“Oz has been a really good defender for us, especially at third,” Boone said. “So hopefully this puts him in a little bit better role, too.”

Peraza, who owns a .152/.212/.241 slash line, has the most starts (34) at third of any Yankee this season. He started there for the 10th time this month on Friday night.

Notes & quotes: Boone said “there’s probably a good chance” that Luis Gil (right lat strain) will make a fourth rehab start .  .  . Mark Leiter Jr. (left fibula head stress fracture) threw a bullpen session on Friday .  .  . Boone said Ryan Yarbrough (right oblique strain) threw a “touch and feel” bullpen session on Friday. “I know he finally feels like he’s through it,” Boone said. “Now it’s just getting built up.” .  .  . Fernando Cruz (left oblique strain) started his throwing program, and Boone said “the hope is that he would be on the mound sometime next week.”

SUBSCRIBE

Unlimited Digital AccessOnly 25¢for 6 months

ACT NOWSALE ENDS SOON | CANCEL ANYTIME