BOSTON — Mike Napoli homered with two outs in the 11th inning — his second home run of the game — and the Boston Red Sox beat the New York Yankees 8-7 on Sunday night.

The Red Sox scored seven runs after falling behind 3-0, thanks in part to Napoli’s three-run homer in the third. But they coughed up the lead when New York scored two in the sixth and two in the seventh to tie it 7-all.

It stayed that way until Napoli hit a 3-2 pitch from Adam Warren (1-1) into the center field bleachers.

Pedro Beato (1-0) pitched the 11th for the win, giving up a single to Eduardo Nunez before he was erased trying to steal second; replays showed he was barely safe.

Nunez, Brett Gardner and Robinson Cano had three hits apiece for the Yankees.

Napoli also struck out three times and grounded into an inning-ending double play with the bases loaded in the eighth. The Yankees had runners at first and second with one out in the 10th, but Drake Britton, making his second major-league appearance, got Lyle Overbay to ground into a double play.

The victory left the Red Sox at 60-40 through their first 100 games, 1½ games in front of the Tampa Bay Rays in the AL East and seven in front of the fourth-place Yankees. Boston won the three-game series between the longtime rivals on a weekend when New York learned that both shortstop Derek Jeter and third baseman Alex Rodriguez won’t be able to return from the disabled list any time soon.

Boston moved Ryan Dempster up in the rotation to give Jon Lester a couple of extra days’ rest after the All-Star break, but things started off poorly for the Red Sox right-hander.

Gardner, who also had three hits on Saturday, led off the game with a single, and then went to third when Dempster fielded Ichiro Suzuki’s comebacker and threw it into center field for an error. Suzuki stole second, and catcher Jarrod Saltalamacchia threw the ball into center for another error that allowed Gardner to score and Suzuki to move to third. He scored on Vernon Wells’ single to make it 2-0.

New York took a 3-0 lead in the second on Cano’s RBI single.

The Red Sox rallied with a four-run third inning, taking the lead on Napoli’s three-run homer that cleared the seats above the Green Monster and a billboard above them. Shane Victorino added a two-run single in the fourth on a high chopper that bounced over the third baseman’s head, and Jonny Gomes homered in the fifth to make it 7-3.

But The Yankees scored two in the sixth on RBI singles by Gardner and Cano before Overbay hit into an inning-ending double play. They tied it 7-all in the seventh on two singles, two walks — one of them a 15-pitch at-bat by Gardner — and third baseman Jose Iglesias’ error when he charged a bunt and threw the ball into the photographers’ box.

That saved CC Sabathia from the loss, despite following up his worst start of the year with one almost as bad. He allowed seven runs on nine hits, two walks and two hit batters, striking out five in five-plus innings.

CLAY BUCHHOLZ is planning to see Dr. James Andrews for a lingering neck strain that’s had the ace right-hander on the disabled list since early June.

Manager John Farrell said the 28-year-old Buchholz was expected to be on the field throwing when the team took batting practice prior to Sunday’s game against New York, but he was going for a second opinion on Monday regardless of the outcome of his workout.

Buchholz was off to a tremendous start this season, going 9-0 with a 1.71 ERA before suffering the injury on June 8.

RELIEVER ANDREW BAILEY will have season-ending right shoulder surgery Wednesday in New York.

He missed almost all of last season after right thumb surgery during spring training.

FOR ONE DAY at least, Mariano Rivera made the whole Red Sox-Yankees rivalry look silly.

Rivera, the most respected player of his generation and the best closer in the history of his sport, spread his brand of love and kindness all over the Red Sox and Fenway Park Saturday.

Rivera went out of his way to connect with Boston and the Red Sox, part of his goodwill farewell tour in which he meets with a select group in each city the Yankees visit during his 19th and final season as a player.

His pregame visit took place in a Fenway suite where fans – young and old, some with cancer, victims of the Boston Marathon bombings – along with longtime Fenway employees sat in a semicircle around the 43-year-old Rivera, who was dressed in his practice uniform.

His greeting was essentially his thanks to them for being there.

“The game of baseball is medicine, I would say,” said Rivera. “Thank god for baseball. For a few hours, we can forget things that happen around us – the bombings that happened at the marathon. Amazing, but that brings us together.”