Baltimore‘s Manny Machado, right, celebrates his go-ahead three-run home run with Nate McLouth (9) and Chris Dickerson in the ninth inning. (Michael Dwyer/Associated Press)

Crazy things happen when the Baltimore Orioles come to Fenway Park.

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 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 non-sellout 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.”

The Orioles have won 10 of their past 14 against the Red Sox (5-3) and 12 of their last 17 at Fenway. This victory snapped a three-game losing streak.

After a 43-minute rain delay, Orioles reliever Tommy Hunter allowed back-to-back homers to give the Red Sox a 5-3 lead. After Hunter exited, the Orioles bullpen threw three perfect relief innings, including a scoreless ninth from closer Jim Johnson.

“Our guys battled,” Orioles Manager Buck Showalter said. “[It was] a really nasty night to play. It’s very easy to give in, but it was a battle and I’m real proud of them. Their bullpen is something. To be able to string together an inning like that [is something].

— Baltimore Sun