The Yankees’ pitching pain only gets worse.

While general manager Brian Cashman stood idle at the MLB trade deadline sans a minor league trade, the Astros acquired ace Zack Greinke from the Diamondbacks on Wednesday, The Post’s Joel Sherman confirms.

The former Cy Young winner is 10-4 with a 2.87 ERA in 22 games this season and forms a daunting top to the Houston rotation with Justin Verlander and Gerrit Cole.

Greinke pitched five innings of two-run ball and struck out seven against the Yankees in The Bronx on Wednesday, and was seen leaving The Stadium after news of the trade broke.

AL West-leading Houston also acquired Aaron Sanchez and Joe Biagini from Toronto to solidify their pitching staff. The Astros sent highly touted first baseman Seth Beer, infielder Josh Rojas, pitcher Corbin Martin and top pitching prospect J.B. Bukauskas to Arizona for Greinke and $24 million.

Greinke, 35, had a no-trade clause, and it’s unclear whether the Yankees were on it. Regardless, the Yankees now will have an even tougher time getting to the World Series.