BOSTON – Josh Beckett found a way to beat the New York Yankees this season, over and over again.

Beckett pitched well enough Wednesday night for Boston to win 9-5, improving to 4-0 against the Yankees this season with a 1.85 ERA. Last season, his worst in the majors, he was 1-2 with a 10.04 ERA against New York.

“The Yankee-Red Sox thing has been here before I got here for a long time and it will be here long after I’m here,” Beckett said. “The big thing is we’re both really good teams and there’s a reason why you’ve got to play those games a little differently.”

Boston is 5-0 in his starts against New York, but credited his offense for Wednesday’s win. Jacoby Ellsbury hit a tie-breaking two-run homer in the sixth, making it 7-5. David Ortiz and Jason Varitek also had two-run shots.

“I might get the win next to my name,” said Beckett (12-5). “I’d say I contributed by eating up some innings, but the guys that probably stuck out all year, they stuck out again today.”

He said the difference from last year, when he was 6-6 with a 5.78 ERA, is his ability to execute pitches in key situations.

The Red Sox, who lost the series opener 5-2 on Tuesday night, extended their AL East lead over the Yankees to 1½ games and improved to 11-3 this season against them.

“We can’t think about what happened until this point,” Derek Jeter of the Yankees said. “If we did, we might as well let them have the rest of the games.”

The Yanks had one big inning against Beckett, four runs in the sixth — the same amount they managed in his previous 32 innings against them this season — and went ahead 5-4.

“I wouldn’t say we’ve figured him out,” Jeter said. “We were able to score those five runs. It wasn’t enough.”

In the bottom of the sixth, Phil Hughes (4-5) retired the first batter. Then he went ahead of Josh Reddick 0-2 before walking him, and Reddick scored the tying run on Varitek’s double. After Marco Scutaro flied out, left-hander Boone Logan came in to face Ellsbury. On a 3-and-1 count, Ellsbury hit his 24th homer into the left-field seats.

“I know (Ellsbury) has been tougher on right-handers,” Boston Manager Terry Francona said, “but he’s no day at the beach for left-handers.”

Beckett allowed four earned runs and six hits through seven innings. He struck out eight and walked three.

Daniel Bard and Jonathan Papelbon each pitched a scoreless inning and the Red Sox improved to 62-3 this season when leading after six.

The Yankees had taken a 1-0 lead in the third on Jeter’s RBI single. The Red Sox went ahead 2-1 in the bottom of the inning, scoring on Dustin Pedroia’s groundout with runners at second and third, and on Jed Lowrie’s RBI single.

Jeter got his second single in the top of the fifth, moving into 20th place all time, ahead of Craig Biggio, with 3,061 career hits. He was left stranded.

Boston made it 4-1 in the fifth on Ortiz’s homer into the center-field bleachers after Adrian Gonzalez singled. It was Ortiz’s 28th homer and extended his hitting streak to 14 games.

The Yankees regained the lead in the sixth, helped by an error by right fielder Reddick.

Mark Teixeira was hit by a pitch leading off the inning, took second on a wild pitch by Beckett and scored on a double by Robinson Cano. Nick Swisher then walked and Eric Chavez followed with a liner down the right-field line. It got by Reddick and Chavez was credited with a double. The error allowed him to take third and Swisher to score. Eduardo Nunez’s sacrifice fly put the Yankees on top 5-4.

Varitek gave the Red Sox a four-run cushion in the eighth with his 10th homer.