The Yankees' pursuit of Athletics starter Sonny Gray spilled into the final hours before the trade deadline, but a swap has been agreed to that will send the right-hander to New York, a source confirmed to ESPN.

The Athletics are getting back shortstop Jorge Mateo, outfielder Dustin Fowler and pitcher James Kaprielian, according to multiple reports. Oakland is taking on two injured players, as Fowler ruptured the patellar tendon in his right knee during his first game in the majors last season while Kaprielian underwent Tommy John surgery earlier this year.

Gray is under club control through the 2019 season. He is making $3.6 million this season and is arbitration eligible in 2018.