This wasn't a 17-inning game. No position players had to pitch. But the comeback the Orioles staged Wednesday night was one they needed to salvage this three-game series at Fenway Park.

Trailing by two runs, the Orioles rallied for a five-run ninth inning against Boston closer Joel Hanrahan, capped by Manny Machado's three-run homer over the Green Monster in left field that gave them a dramatic 8-5 win.

“It was a huge win for us,” Machado said. “We were really never ahead the whole game, and to come out with the victory, it is really going to give us the big boost we needed to get this show going.”

First baseman Chris Davis opened the ninth with his team-leading fifth homer of the season, a mammoth shot to straightaway center. With two outs and the Orioles (4-4) still trailing by a run, second baseman Ryan Flaherty, mired in an 0-for-17 slump to open the season, singled through the hole at short. Nolan Reimold and Nate McLouth walked to load the bases for Machado.

Hanrahan's first pitch to Machado was wild, allowing pinch-runner Alexi Casilla to score the tying run.

Then Machado took a 95-mph fastball from Hanrahan — who threw 32 pitches in the inning — over the Green Monster, silencing what was left of an announced crowd of 30,862, the first nonsellout at Fenway in 795 regular-season games.

Up until Machado's game-winning hit — which was his first career homer in the ninth inning or later — the Orioles struck out 13 times and were 1-for-7 with runners in scoring position. Machado had come to the plate with just one hit in his previous 18 at-bats.

“I've been sticking with the approach that I've had the whole season, sticking to it and not trying to change anything,” Machado said. “That's how you dig yourself into a deeper hole. I just went up there trying to stay with the same approach I've had. And it paid off, finally.”