Chris Davis set a new Orioles’ record by blasting his 51st home run of the season, breaking the mark held by Brady Anderson. (Jim Rogash/Getty Images)

On a night when slugger Chris Davis made Baltimore Orioles history with his 51st home run of the season — setting a single-season franchise record — the team’s hero was its unheralded hottest hitter.

The Orioles beat the Red Sox, 3-2, on Tuesday night, fueled by Danny Valencia’s leadoff triple in the ninth inning off Red Sox closer Koji Uehara.

Valencia’s hit snapped Uehara’s franchise-record 37 straight retired hitters, and one batter later, Matt Wieters’s sacrifice fly to right ended the former Oriole’s streak of 301 / 3 scoreless innings.

Valencia, who had grasped the everyday DH role, is hitting .405 (15 for 37) in September after reaching base three times on Tuesday (1 for 2 with two walks).

Despite allowing a one-out hit in the ninth, Jim Johnson recorded his 46th save of the season, capping four scoreless innings by the Baltimore bullpen.

With the win over the Red Sox in front of 35,030 at Fenway Park, the Orioles (80-60) remained two games back of both of the two American League wild-card spots, which are now tied between Tampa Bay and Texas after the Rangers’ 7-1 win over the Rays.

With just 12 games remaining in the regular season, the Orioles desperately needed a win in Boston on Tuesday night.

In his third at-bat, Davis crushed a 2-1 slider into the center field stands off Boston right-hander Ryan Dempster in the sixth inning to tie the game at 2.

Davis’s shot passed Brady Anderson’s previous club record of 50 homers set in 1996.

Twenty-three of Davis’s homers have either tied the game or given the Orioles the lead.

Davis struck out against Dempster in his previous two at-bats on Tuesday and was 2 for 13 with eight strikeouts against Dempster in his career heading into the at-bat.

The Orioles were able to recover the ball out of the stands from a Red Sox fan who requested another baseball autographed by Davis in exchange.

Deadlocked in a 2-2 game in the eighth inning, the Orioles had runners at second and third with no outs, but couldn’t score the go-ahead run as Baltimore went 0 for 6 with runners in scoring position before Wieters’s sac fly.

After Nate McLouth led off the inning with a single to right, third baseman Manny Machado hit his majors-leading 51st double down the right field line, putting runners at second and third.

But against a drawn-in infield protecting the run, the Orioles’ top two sluggers, Davis and Adam Jones, failed to get the ball out of the infield with back-to-back groundouts to shortstop. Nick Markakis ended the inning with a flyout to left.

Orioles right-hander Scott Feldman struggled with his control, issuing a season-high six walks, including four with two outs, despite allowed just two runs — one earned —on two hits through five innings.

Five pitches into the game, Feldman allowed a solo homer to Red Sox leadoff hitter Dustin Pedroia over the Green Monster in left field.

Feldman allowed at least one base runner in every frame, but he overcame his wildness, getting a pair of key double plays to limit the damage.

The Orioles, who entered the night with 113 errorless games this season — tying the 2008 Houston Astros for most since 1900 — committed their first three-error game since June 27, 2012 against the Angels.

— Baltimore Sun