AP Sports Writer
NEW YORK (AP) -- With every ball out of the strike zone in the seventh inning, Wade Miley got angrier and put himself in deeper trouble.
David Hernandez needed just one pitch to spoil his outing.
Hernandez gave up a pinch-hit homer to Travis Hafner in the eighth inning and the Arizona Diamondbacks lost to the Yankees 4-3 Wednesday, failing to protect an early lead for the second straight night against New York.
Miley took a three-run lead into the seventh but was chased after walking Eduardo Nunez to load the bases and Jayson Nix to make it 3-1 with two outs.
"When I walked Nunez I was just kind of trying to throw it 100 mph to the next guy," Miley said. "I just kind of got frustrated, and I started pulling off a little bit and just walked two in a row."
Brett Gardner then had a tying, two-run single off Tony Sipp. Stymied by Miley for six innings, the Yankees broke through and won for the seventh time in eight games.
Hernandez (0-1) got two quick outs to start the eighth but left a fastball over the middle of the plate for Hafner, who was batting for Ben Francisco.
Hafner sent a drive into the stands in right-center for his fourth home run. It was the fourth career pinch-hit homer for Hafner, and his first since joining the Yankees in the offseason.
"I definitely wish I would have had that pitch back," Hernandez said. "I wish I would have slowed the game down a little bit more, but it was just a bad pitch. I knew that he was probably geared for a fastball right there, so I just didn't throw it where I wanted to throw it."
Hernandez's loss was the first for Arizona's bullpen this season, dropping the group to 3-1.
CC Sabathia (3-1) gave up an opposite-field, two-run homer to Paul Goldschmidt in the first -- one of three hits in the opening inning -- then only three more hits and a sacrifice fly to A.J. Pollock through the eighth.
Sabathia struck out six and walked one in his third straight win after struggling on opening day. It was his second straight outing of eight innings.
Mariano Rivera pitched the ninth for his fourth save, closing out a game that took just 2 hours, 28 minutes. Injured for most of last season, Rivera posted his first back-to-back saves since April 10-11, 2012.
New York failed to get a runner to second base against Miley until Vernon Wells doubled with two outs in the sixth.
"He's a good looking pitcher," Yankees manager Joe Girardi said. "He gets you to swing at that ball that's just above the waist and looks really tempting."
Francisco, the only member of New York's lineup to face the left-hander before Wednesday, singled with one out in the seventh to start the tying rally.
After Francisco Cervelli struck out, Brennan Boesch doubled and Eduardo Nunez walked to load the bases. Calm and working quickly early, Miley took the throw back after the walk and stomped around the mound. He then walked Jayson Nix to make it 3-1 with several high fastballs.
Miley snatched the ball and stalked around the mound some more before manager Kirk Gibson called for Tony Sipp. Miley bit down hard on a towel in the dugout while Sipp warmed up.
"He was great," Gibson said of Miley. "His pitch count was low. He just didn't throw the ball where he wanted to when he needed to in the seventh inning."
Gardner then slapped a two-run, opposite-field single to left to make it 3-all. The runners advanced to second and third on the offline throw home and side-armer Brad Ziegler relieved and got Wells to ground out.
"I thought Wade pitched enough to get a win right there. Disappointing," Sipp said. "My job is to come in and get a batter out, and I didn't do my job."
The Diamondbacks got off to a good start against Sabathia. Pollock doubled leading off and Goldschmidt homered. They put two more on base with one out, but Sabathia struck out Alfredo Marte and got Gerardo Parra to fly out.
"I was all over the place and got a changeup up," Sabathia said of the pitch to Goldschmidt.
The Diamondbacks added a run in the fifth. Playing second base for the injured Aaron Hill, Josh Wilson hit a drive to right-center and Gardner made a long run before attempting an awkward diving catch. But the ball fell out of Gardner's big glove before he hit the warning track hard and Wilson made it to third base with a triple. He scored with a headfirst slide on Pollock's sacrifice fly to right field.