BALTIMORE — Tim Beckham and Jonathan Schoop homered and drove in three runs each, and the Baltimore Orioles withstood four long balls by the Boston Red Sox in a 7-6 victory Tuesday night.

It was only the third loss in 18 games for the Red Sox, who have the best record in the major leagues (71-32) and a five-game lead over the New York Yankees in the AL East.

Baltimore closer Zach Britton was not used in a save situation. A person familiar with the talks told The Associated Press the Yankees are close to agreement on a trade to acquire Britton for three prospects. The person spoke on condition of anonymity because the deal would be subject to the teams approving medical records.

Brad Brach, another reliever the Orioles want to trade, worked the ninth in the rain for his 11th save. Brach put the potential tying run on second base before getting Mookie Betts to hit into a game-ending double play.

Staggering through the season with the worst record in the big leagues at 29-73, the Orioles started the rebuilding process last week by trading All-Star shortstop Manny Machado to the Los Angeles Dodgers. Victories have been hard to come by for Baltimore, especially against Boston.

With Schoop and Beckham leading the way, the Orioles beat the Red Sox for just the second time in 12 games this year and stopped a nine-game home losing streak against their division rivals.

J.D. Martinez homered twice to raise his season total to 31, and Betts and Blake Swihart contributed solo shots for the Red Sox.

Coming off the disabled list to make his first big league start since May 31 after recovering from left biceps tendinitis, Boston left-hander Drew Pomeranz (1-4) gave up four runs and six hits in 4 2/3 innings. He yielded a two-run homer to Schoop in the third inning and a two-run drive to Beckham in the fifth.

Orioles rookie starter Yefry Ramirez (1-3) yielded three long balls but he struck out six in five innings and earned his first major league victory.

Baltimore made it 7-3 with a three-run sixth as Beckham, Schoop and Adam Jones delivered RBI singles.

TRAINER’S ROOM: Red Sox: The return of Pomeranz makes it easier for Boston to cope with the loss of LHP Eduardo Rodriguez (ankle sprain). “He was one of the best pitchers in the league last year,” manager Alex Cora said of Pomeranz. “Hopefully, we’ll have him for the rest of the season now.”

STOCKED BULLPEN: Red Sox optioned SS Tzu-Wei Ling to Triple-A Pawtucket to make room for Pomeranz. That left Cora with a short bench and eight relief pitchers. “I love the bullpen the way it is right now,” the manager said. “I like having the extra guy out there.”

UP NEXT: Red Sox: David Price (11-6, 4.17 ERA) works the series finale Wednesday night. Price is 7-0 lifetime at Camden Yards and 13-5 overall against the Orioles.

Orioles: Dylan Bundy (6-9, 4.57 ERA) starts for the Orioles, seeking to end a run of three starts in which he’s allowed 16 runs over 12 1/3 innings.