BOSTON — For the second straight night, the Baltimore Orioles pulled out a vital road victory over the Boston Red Sox.

And for the second straight night, Chris Davis was right in the middle of the fun.

Tuesday night, Davis broke the club record with his 51st homer of the season in what turned out to be a 3-2 win. Wednesday night, Davis, 0-for-5 when he stepped to the plate with the bases loaded and two out in the 12th inning, bounced a two-run single up the middle to give the Orioles a 5-3 victory.

“Any time you’re in a game like that you want to be the guy to get the hit, whether it’s a squibber up the middle or a home run,” Davis said. “You can feel the intensity with both teams going out there trying to get a run. I’ll take it however I can get it.”

By winning for the fourth time in the last five games, the Orioles moved to within a game of a wild-card spot.

With one out in the 12th inning, J.J. Hardy and Brian Roberts singled and the runners moved up on a wild pitch. Pinch-hitter Steve Pearce was intentionally walked by Franklin Morales (2-2).

Manny Machado fouled out. Davis hit a fastball to make a winner of T.J. McFarland (2-1).

It was last season, in a game at Fenway Park, that Davis was 0-for-8 and ended up pitching two innings to earn the victory in a 17-inning game. His career has taken off since that May game, with Davis becoming a powerful offensive threat.

“We were going to try to stay away from Chris Davis (pitching) tonight,” said manager Buck Showalter.

Asked again about his slugger, Showalter said, “You kind of run out of adjectives to describe what he’s done.”

The RBIs were the 133rd and 134th of the season for Davis, a MVP candidate along with last season’s winner, Detroit’s Miguel Cabrera.

Jim Johnson pitched the bottom of the 12th for his 47th save, capping a 6 1/3 scoreless outing for the bullpen, a night after a four-inning scoreless outing.

The Red Sox came in again needing a win and a Cleveland loss to clinch their first playoff spot since 2009. They got the Cleveland loss, but couldn’t come through themselves, scoring just three runs on 15 hits as their magic number for clinching their first division title since 2007 stayed at three.

“We gave ourselves plenty of opportunities,” said Boston manager John Farrell. “A lot of good things went on in that game. We put a lot of guys on bases, but they make a key pitch in a key situation.”

Baltimore turned four double plays (seven in two games), two of them in extra innings, as the Orioles, on their way to shattering the major league record for fewest errors in a season, set the big-league mark (since 1900) with their 114th errorless game.

They did make some mistakes, failing to turn two other double plays. Second baseman Roberts botched a grounder that was ruled a hit, but they also did what they had to do to win.

Jake Peavy went the first seven innings for Boston, while Wei-Yin Chen worked the first 5 2/3 for the Orioles, allowing 11 hits, but only three runs.

“That’s a good ballclub,” Peavy said of the Orioles. “We knew at the start of the season they were going to be in it. Nothing comes easy in major league baseball, much less in the (American League East).”

David Ortiz and Mike Napoli hit solo homers and Will Middlebrooks and Shane Victorino had three singles apiece for Boston. Matt Wieters drove in two runs for the Orioles.

The Red Sox, already ahead 2-0 on the Ortiz homer, had a chance to add more in the third when they loaded the bases with nobody out on three singles. Napoli and Jonny Gomes, who combined 15-for-29 with four homers and 42 RBIs (31 by Napoli) with the bases loaded this season, were due up. Napoli was retired on a soft liner to short. Gomes hit the ball back to the mound, Chen starting a 1-2-3 double play.

Peavy held the Orioles, hitless through four innings but the fifth was a different story when the Orioles tied the game on long doubles by Wieters and Roberts.

NOTES: The top four hitters in the Orioles lineup were a combined 0-for-20 when Davis delivered his two-run single in the 12th inning. … Middlebrooks snapped an 0-17 skid with a second-inning single. … Victorino had to be pinch-hit for in the 12th inning because of a jammed right thumb. … In honor of Boston’s ZZ Top bearded look, Wednesday night was “Fenway Dollar Beard Night,” with fans sporting any kind of beard, real or otherwise, allowed to purchase tickets for $1. The Red Sox announced that more than 4,000 tickets were sold. … Showalter hopes to have RHP Bud Norris (elbow) back for his Saturday start at Tampa Bay. If Norris can’t go, there’s a chance RHP Miguel Gonzalez, who left his last start with a right groin strain, might be ready (sooner than expected).