The Yankees have traded starting pitcher Sonny Gray to the Cincinnati Reds, the teams announced Monday, finalizing a days-in-the-making deal that ends Gray's topsy-turvy stint with New York.

Both sides completed a deal that was contingent upon the Reds reaching a contract extension with the 29-year-old Gray, who agreed to a three-year, $30.5 million extension that includes a $12 million club option for 2023, a source familiar with the deal told ESPN. Combined with his $7.5 million salary this season, Gray's deal can max out at five years and $50 million.