PHOENIX — The Pittsburgh Pirates had what looked like an out turn into a home run. They made a couple of questionable decisions, endured some nerve-wracking moments in the ninth inning.

But they're leaving Arizona with a win, which is all that really matters. Everything else can wait.

Jordy Mercer homered and had three RBIs, Jameson Taillon pitched seven effective innings and the Pirates avoided a sweep with a 5-4 victory over the Diamondbacks on Wednesday.

"We won. Let's get on a plane and go home," Pirates manager Clint Hurdle said. "We can peel back the layers later."

The Pirates blew a five-run lead in the opener and were knocked for 13 runs in the second game. Pittsburgh ended Arizona's sweep bid with a four-run second inning against Zack Greinke (5-5) and a sterling performance by Taillon (4-5).

Taillon gave up a two-run homer to David Peralta in the first inning when the ball popped out of left fielder Austin Meadows' glove and over the wall. Taillon got better as the game went along, working out of a jam in the second inning and allowing two runs on six hits to help end Arizona's five-game winning streak.

Felipe Vazquez gave up a two-run single to pinch-hitter Jon Jay in the ninth before striking out Jake Lamb with the bases loaded for his 12th save.

"When you run into a team that's pesky with two strikes, they're tough to put away," Diamondbacks manager Torey Lovullo said. "You're going to run into some situations when you make mistakes."

Taillon has enjoyed pitching in the afternoon, entering Wednesday's game 8-2, including 3-0 on the road before the sun goes down. He got an unfortunate break in the first inning, when Peralta's deep shot caromed out of Meadows' glove as he leaped near the wall.

Taillon struck out Paul Goldschmidt with the bases loaded to end the second inning and struck out four.

"It was a weird start, but I felt really good," Taillon said. "I kind of had that mindset, like let's see if I could get my pitch count right through six."

Greinke has been dominant at Chase Field the past two seasons, going 16-1 with 2.53 ERA at Chase Field since 2017.

Arizona's ace struggled with his command against the Pirates, walking four while striking out seven. Greinke walked two in Pittsburgh's four-run second inning, giving up a two-run double to Mercer and a run-scoring double to Josh Bell. Mercer hit a solo homer in the fourth to put Pittsburgh up 5-2.

Greinke was lifted after walking two in the fifth to load the bases with two outs. He allowed five runs on five hits and struck out seven.

"I felt good, but every time I put a pitch over the plate, they hit it good," said Greinke, who had not lost at Chase Field since last Aug. 9 against the Los Angeles Dodgers. "As long as I'm able to make good pitches it's fine, but I wasn't able to do that every time."

MEADOWS' MISCUE

One of the things the Pirates will look at when they get home is Meadows' miscue that led to Peralta's home run. He leaped to catch the ball just before colliding with the wall, but the ball appeared to carom out before contact was made.

"I haven't said anything to him; we'll show him the video," Hurdle said. "There's room to go get the ball and it kind of looked like it was the fence or he drifted on the ball, there was hesitation. He had time to get under that ball or at least get to it quicker."

DIAMONDBACKS MOVES

Arizona reinstated C Jeff Mathis from paternity leave and optioned RHP Braden Shipley to Triple-A Reno. Mathis' wife, Jenna, gave birth to their second daughter on Sunday.

TRAINER'S TABLE

Pirates: C Francisco Cervelli returned to the lineup after missing three games while being monitored for post-concussion symptoms. He was struck on the mask by a foul ball Saturday against the Chicago Cubs.

Diamondbacks: LHP Robbie Ray (strained right oblique) is expected to throw about 50 pitches in his rehab start with Single-A Visalia on Thursday.

UP NEXT

The Pirates have a day off before right-hander Chad Kuhl the Cincinnati Reds Friday at home. Kuhl is 1-1 with a 2.78 ERA in four career starts against the Reds.

Arizona RHP Matt Koch is 2-0 with a 5.29 ERA his past three starts heading into Thursday's game against the New York Mets.

___

More AP baseball: https://apnews.com/tag/MLBbaseball