BOSTON — David Lough hit a three-run homer in Baltimore’s four-run second inning and the Orioles beat the Boston Red Sox 6-4 on Tuesday night, their 12th win in 15 games.

The Red Sox had a chance to tie it in the ninth after Dustin Pedroia’s two-out, run-scoring double. But David Ortiz lined out to third as Zach Britton earned his 20th save.

Lough, starting for the sixth time in seven games in place of injured center fielder Adam Jones, connected off Joe Kelly (2-5) after a sacrifice fly by Ryan Flaherty.

Baltimore made it 5-1 in the fourth on an RBI single by Jimmy Paredes and 6-3 in the sixth on a run-scoring double by Manny Machado.

Boston scored single runs in the third, fourth and fifth off Ubaldo Jimenez (6-3)

Red Sox manager John Farrell was ejected after a called third strike to Brock Holt ended the sixth. The pitch appeared to be outside and Farrell was ejected when he argued with plate umpire Tim Timmons.

The Red Sox returned from a promising road trip with renewed hope after winning three of their last four games. They remained a distant last in the AL East but showed signs that their weak hitting was improving by scoring 29 runs in those four games.

But Jimenez, who has allowed three earned runs or less in 12 of his 14 starts, and four relievers from one of baseball’s best bullpens held them to eight hits, just two in the last four innings.

The Orioles went ahead in the second when they loaded the bases on singles by the first three batters, Chris Davis, Travis Snyder and J.J. Hardy. After Flaherty’s sacrifice fly, Lough, the usual starting left fielder, hit his fourth homer of the season.

The Red Sox cut the lead to 4-1 in the third on a single by Sandy Leon, a double by Mookie Betts and a run-scoring groundout by Holt. They made it 5-2 in the fourth when Hanley Ramirez singled, advanced on a wild pitch and scored on a single by Pablo Sandoval.

They drew within two runs in the fifth when Pedroia and Ortiz walked with two outs and Ramirez singled in Pedroia.

But after Flaherty walked and was sacrificed to second by Lough in the sixth, Machado doubled him home.