PITTSBURGH -- Starling Marte hit a tying two-run triple in the ninth inning then scored the winning run on Ike Davis' single as the Pittsburgh Pirates rallied for a 3-2 victory over the Arizona Diamondbacks on Tuesday night.

Diamondbacks left-hander Wade Miley carried a two-hit shutout into the ninth but was lifted after giving up back-to-back singles to second baseman Neil Walker and pinch-hitter Gregory Polanco to start the inning.

With Miley's pitch count at 111, Diamondbacks manager Kirk Gibson called on closer Addison Reed (1-4), who suffered his fourth blown save in 23 chances.

Right fielder Josh Harrison flied out to center field and Walker advanced to third before Marte, the left fielder, drove a triple off the top of center-field fence to tie the score.

Center fielder Andrew McCutchen was intentionally walked and Davis, pinch hitting for first baseman Gaby Sanchez, lined a single to right to score Marte and give the Pirates their eighth win in the last 10 games.

Reliever Ernesto Frieri (1-0), who pitched a scoreless top of the ninth despite giving up three hits, got his first win with the Pirates. He was acquired from the Los Angeles Angels last Friday in a trade.

Miley went into the ninth looking for his first shutout and complete game of his four-year career. He retired the first 14 batters before shortstop Jordy Mercer singled with two outs in the fifth inning.

Miley, winless in his last nine starts, gave up two runs and four hits with no walks and 10 strikeouts.

Left-hander Jeff Locke pitched effectively for the Pirates and was taken on the hook for what would have been a tough loss with the ninth-inning rally. He allowed two runs and eight hits in eight innings, walking one and striking out three.

Locke has a 2.23 ERA in five starts since being recalled from Triple-A Indianapolis on June 8.

First baseman Paul Goldschmidt and left fielder David Peralta had two hits each for the Diamondbacks.

After leaving runners on base in each of the first four innings, the Diamondbacks scored the game's first two runs in the fifth on back-to-back, two-out RBI singles by catcher Miguel Montero and second baseman Aaron Hill.

NOTES: Arizona LF Mark Trumbo was scheduled to begin a rehab assignment in the rookie-level Arizona League on Tuesday night. Trumbo has been out since April 22 with a stress fracture in his left foot. ... Diamondbacks SS Chris Owings underwent an MRI exam that showed no structural damage in his left shoulder. Owings, on the disabled list since June 26, is cleared to begin throwing but won't be allowed to hit for another week. ... Pirates C Russell Martin returned to the lineup after missing the previous two games with a sore left shoulder. ... Pittsburgh RF Gregory Polanco got his first day off since being called up from Triple-A Indianapolis and making his major league debut June 10. ... Pirates LHP Francisco Liriano will pitch a four-inning simulated game Wednesday, the first time he will face hitters since going on the disabled list June 11 with a strained left oblique. ... Diamondbacks RHP Chase Anderson (5-3, 3.63 ERA) will face RHP Charlie Morton (4-9, 3.41) on Wednesday night.