The Diamondbacks also are sending New York cash in Sunday's deal for left-hander Vidal Nuno. The trade was announced by the Yankees.
A source told ESPN The Magazine's Buster Olney that the Diamondbacks will eat $2.05 million of the $4.1 million owed to McCarthy for the rest of the season. The Yankees will pay the $1 million in McCarthy's assignment bonus.
The move comes after Yankees left-hander CC Sabathia had a setback with a degenerative cartilage problem in his right knee. New York was unable to work out a trade this week for the Cubs' Jeff Samardzija, who instead was dealt to Oakland.
McCarthy, who turns 31 on Monday, was 3-10 with a 5.01 ERA with Arizona this season. In nine seasons with the White Sox, Rangers, A's and Diamondbacks, McCarthy is 45-60 with a 4.21 ERA.
"McCarthy is an experienced starter, that we expect to pitch well for us," Yankees manager Joe Girardi said. "I know he's had his struggles, but he's seemed to turn it around. He has a good arm. His last few starts have been pretty good."
McCarthy said he was informed of the deal after he reported for Sunday's game against the Braves. He will leave the last-place Diamondbacks and join a playoff race with New York.
"It's something I'm really excited about," McCarthy said.
McCarthy said he is sad to be leaving Arizona, but added the move to New York is special.
"It's still the Yankees, no matter what," McCarthy said. "If you don't know baseball, you know the Yankees."
McCarthy also reacted to the trade on his Twitter account.
Yankee pinstripes, awesome. Very slimming but awesome.- Brandon McCarthy (@BMcCarthy32) July 6, 2014
McCarthy planned to fly from Atlanta to meet the Yankees in Cleveland, where they open a series on Monday.
Nuno, 26, was 2-5 with a 5.42 ERA in 17 games, including 14 starts, with the Yankees. Nuno was hurt by allowing 15 homers -- including 13 at home -- in 78 innings this season.
"It's been kind of a tough day," Girardi said. "Nuno did a great job for us, stepped in and did a good job for us last year, but it's an opportunity for him to start in Arizona and I know he appreciates that as well."
McCarthy, a groundball pitcher, may be better suited for Yankee Stadium.
Yankees general manager Brian Cashman sought an upgrade to the rotation for weeks. Sabathia is out indefinitely and the Yankees also lost Ivan Nova to Tommy John surgery.
The Diamondbacks have made two trades in as many days. On Saturday, Arizona acquired two minor leaguers, outfielder Zach Borenstein and right-hander Joey Krehbiel, from the Los Angeles Angels for left-hander Joe Thatcher and outfielder Tony Campana.
More moves may be coming for Arizona.
"We're going to start retooling, it looks like," Arizona manager Kirk Gibson said Sunday. Gibson called the approach "a different mindset."
Gibson said Nuno will make his debut with Arizona on Tuesday against Miami. Nuno had been scheduled to start for the Yankees on Monday, and Gibson said he wanted to give the young left-hander an extra day to adjust to his new team.
"It's not disappointing, it's part of baseball," Nuno said. "It is what it is. Close to home, family see me a little bit more. The journey of coming up here, getting to major leagues and all the opportunities I got, and I appreciate everything [the Yankees] gave me and all the learning experience."
ESPNNewYork.com contributor Andrew Krammer and The Associated Press contributed to this report.