Baltimore’s Danny Valencia, right, slides past Boston Red Sox catcher David Ross to score a run on a double by Steve Pearce during the eighth inning Saturday’s game in Baltimore. The Orioles earned a 6-5 victory.

BALTIMORE — Steve Pearce drove in the go-ahead runs with a double in the eighth inning Saturday night and the Baltimore Orioles rallied to a 6-5 win over the Boston Red Sox, who clinched home-field advantage throughout the postseason earlier in the day.

Pearce’s drive to the left field corner — his second double of the game — came off Franklin Morales and brought home Matt Wieters and Danny Valencia, who both had singled to lead off the inning against Matt Thornton (0-5).

The victory brought a measure of consolation for the Orioles, making them the only AL East team to win the season series against the Red Sox. Boston was assured of the best record in the American League when Oakland lost to Seattle with one day to spare in the regular season.

The Red Sox will open their division series at Fenway Park on Friday against the winner of the wild-card playoff — either Cleveland, Tampa Bay or Texas.

Kevin Gausman pitched 1 1-3 innings to get the win, and Jim Johnson pitched the ninth for his 49th save.

The Red Sox threatened against Johnson when Mike Napoli hit a two-out single and pinch-runner Quintin Berry stole second, but Jonny Gomes was called out on strikes to end the game.

The Orioles lead the season series 10-8 with one to play. The rest of the AL East is 21-36 against the Red Sox.

Daniel Nava tied a career high with four hits, and Dustin Pedroia had three hits and an RBI for the Red Sox, who took a 5-4 lead with a pair of runs in the seventh.

Boston starter Jon Lester gave up four runs and nine hits over five innings. He had gone nine starts without allowing a home run, but that streak was broken by Brian Roberts’ solo drive to lead off the third. The Orioles pieced together four singles in the fifth to produce two runs and take a 4-2 lead, but David Ross’ double in the sixth cut the deficit to one and chased Baltimore starter Wei-Yin Chen.

Chen allowed three runs and nine hits over 5 1-3 innings and ended up with his sixth consecutive no-decision. The Red Sox came back with a pair in the seventh, going ahead with the help of an error by left fielder Jason Pridie, whose bobble on Nava’s single allowed Pedroia to score.

Notes: Orioles CF Adam Jones grimaced and dropped his bat after fouling off a pitch in the seventh. The trainer came out to look at Jones’ left hand, but he stayed in the game and struck out on the next pitch. ... Pedroia is 11 for 19 in his career off Chen. ... Orioles manager Buck Showalter had a thin bench because of injuries to OF Michael Morse and INF Jonathan Schoop. Morse has possible ligament damage in his left wrist and will see a specialist to determine whether he needs surgery, and Schoop will be examined after showing symptoms of a back injury. Schoop was on the on-deck circle as a possible pinch-hitter in the eighth, but he did not bat.