PHOENIX -- Sean Rodriguez lined a double over the head of Arizona left fielder Shelby Miller to drive in the go-ahead run.

Wait. Shelby Miller, the Diamondbacks' No. 2 starter, out in left late in a game?

That was only a small part of the wackiness Sunday at Chase Field.

"Top-five crazy," Pittsburgh manager Clint Hurdle said after the Pirates held off the Diamondbacks 12-10 in 13 innings on Sunday.

A game that started like a blowout quickly devolved into a what-will-happen-next series of blown leads, clutch hits and desperation. The Pirates led by five runs after three innings and blew two-run leads in the ninth and 12th, which set up a back-and-forth of bizarre-but-necessary moves involving pitchers.

Zack Greinke, Arizona's starter on Monday, came in to pinch hit and lined a single during Arizona's 12th-inning rally. He was replaced by Miller, who scored a run as a pinch runner.

Miller had to stay in the game after shortstop Nick Ahmed was ejected for arguing a called third strike. He became the first Diamondbacks pitcher to play a position and the first major leaguer to do so since Jason Gurka played right field for the Colorado Rockies on Sept. 15, according to STATS.

Miller had a hard time tracking down Rodriguez's double off Evan Marshall (0-1) in the 13th, though the run was going to score anyway.

Pittsburgh turned to a pitcher after Rodriguez's hit and sent out Jonathon Niese, the scheduled starter for Wednesday against Colorado. He came through too after battling through a nine-pitch at-bat to line a run-scoring single to left and give the Pirates a two-run lead.

The game ended with Arquimedes Caminero striking out Patrick Corbin, another starting pitcher-turned-pinch hitter, and Miller for his first career save.

"Really, this whole series some weird stuff went on," said Pirates left-hander Kyle Lobstein, who pitched scoreless innings in the 10th and 11th. "At the same time, we still battled. We had some things that didn't go our way, had some bad luck, but we persevered at the end. That's what it's all about."

The Pirates had a season-high 20 hits and were up 8-3 through three innings after roughing up Robbie Ray. Arizona rallied by scoring twice in the eighth, and Paul Goldschmidt tied it in the ninth with a two-run homer, his second of the game.

Pittsburgh scored twice in the 12th to go up 10-8, but Neftali Feliz (1-0) couldn't hold that lead. The Diamondbacks scored two runs off him in the inning but failed to get the winning run, despite having a runner on third with one out.

"The opportunities were in front of us," Diamondbacks manager Chip Hale said. "To get to the point where we think we can be at some point this year, those are spots that we're going to welcome the pressure. Right now, I think we are letting the pressure kind of overwhelm us."

Arizona's Welington Castillo hit a three-run homer on his 29th birthday, which gives him six homers and 11 RBIs in the past seven games. Yasmany Tomas also homered for the Diamondbacks, who had 15 hits.

NUMBERS

Arizona's pitchers had 17 strikeouts, second most in team history at Chase Field. ... Pittsburgh's Mark Melancon had his streak of consecutive saves snapped at 18, after he gave up the two-run homer to Goldschmidt in the ninth. ... Castillo became the eighth Diamondbacks player to homer on his birthday and the first since Justin Upton on Aug. 25, 2012, against San Diego. ... Pirates starter Francisco Liriano allowed four runs on five hits with six strikeouts in six innings. ... Goldschmidt had a rare off-day on defense, with the first two-error game of his career. One came on a squibber by Liriano in the second inning and the other while trying to throw home in the fourth.

TRAINER'S ROOM

Pirates: INF Jung Ho Kang, who is recovering from knee surgery, got his first hit in 15 at-bats for Triple-A Indianapolis.

Diamondbacks: RHP Josh Collmenter (shoulder) will throw in extended spring training this week and is scheduled to go three innings at Class A Visalia on May 2. He could be back for Arizona's next road trip.

UP NEXT

Pirates: LHP Jeff Locke will try for his first win of the season in his fourth start when the Pirates open a four-game series against Colorado on Monday.

Diamondbacks: RHP Greinke, Monday's starter against St. Louis, is 1-0 with a 1.93 ERA his past two starts after a rough debut with Arizona.