BALTIMORE — Mark Trumbo breathed some life into the Baltimore Orioles' post-season hopes.

Trumbo led off the 12th inning with his major league-leading 44th home run, and the Orioles rallied from a late two-run deficit to beat the Arizona Diamondbacks 3-2 on Friday night.

After getting swept in a four-game series by Boston, the Orioles remained a half-game behind Detroit for the AL's second wild card.

"This is the type of game you definitely want to win because it can be a real gut punch if it goes the other way," Trumbo said.

Baltimore trailed 2-0 before Pedro Alvarez homered in the eighth off Enrique Burgos and Matt Wieters homered against Daniel Hudson leading off the ninth.

Oliver Drake (1-0) pitched a scoreless 12th for his first big league win. Matt Koch (1-1) relieved to start the bottom half and Trumbo sent his first pitch over the left-field fence, setting off a celebration. It was Baltimore's sixth walk-off home run this season.

"They did a great job of battling back and tying the game and we did a great job of stopping them from winning the game a couple of times," Diamondbacks manager Chip Hale said. "We had some great plays. We left a ball up there in the middle of the plate for Trumbo and we know what he can do with it. We've seen it before."

Baltimore, which stranded 14 runners, nearly won the game in the ninth. J.J. Hardy tried to score from second on Adam Jones' single but was called out after the throw from left fielder Brandon Drury to catcher Welington Castillo, a play upheld by video review.

"I thought he was safe," Orioles manager Buck Showalter said. "The only thing they could have possibly said that they weren't sure J.J. got there. The guy tagged him with the glove and had the ball in his throwing hand. You've got to help me with that one. I'm sure you all saw the same thing we did. Another head-shaker. We've had quite a few of them this year."

Arizona built a lead against Yovani Gallardo on RBI doubles by Jake Lamb in the first and Jean Segura in the second. Gallardo has allowed 22 runs in the first inning this season.

"You never want to have a start in that way, giving up a run in the first, giving up a run in each of the first two innings," Gallardo said. "It's going to happen."

Arizona's Shelby Miller allowed just three hits in six innings and remained winless since June 20.

"Against a lineup like that, in a tough ballpark to pitch in, it's always tough to throw zeroes," Miller said. "And to get a good outing like that against that team . really the biggest thing was we made a lot of good plays on defence.

DOMINANT BULLPEN

Six Orioles relievers — Darren O'Day, Brad Brach, Mychal Givens, Zach Britton, Tommy Hunter and Oliver Drake — each threw one scoreless inning.

TRAINER'S ROOM

Diamondbacks: RHP Zack Greinke did not travel with the team because of shoulder stiffness. He is expected to have an MRI.

Orioles: RHP Kevin Gausman will likely start Tuesday or Wednesday in Toronto after being pushed back because of soreness in an oblique.

UP NEXT

Diamondbacks: RHP Robbie Ray (8-13, 4.66 ERA), scheduled to start Saturday, entered the weekend fifth in the NL with 210 strikeouts. He is making his first career start against Baltimore.

Orioles: LHP Wade Miley (8-13, 5.65 ERA) returns after leaving in the fifth inning Sept. 18 against Boston with a strained back muscle. Miley, selected by Arizona in the first round of the 2008 amateur draft, is facing his former team for the first time.