BOSTON — Mookie Betts said it was his greatest moment in baseball. David Price told Hanley Ramirez the same thing.

“It’s an honor,” Ramirez said after hitting a three-run homer with two outs in the ninth inning to finish off a five-run rally that gave the Boston Red Sox a 7-5 victory over the New York Yankees on Thursday night.

“Unbelievable comeback,” the Boston first baseman added after helping the Red Sox snap a two-game skid and open a two-game lead in the AL East – knocking their archrivals back in the playoff race at the same time. “This one was a moment I really enjoyed. “

New York took a four-run lead in the third inning and still led 5-1 before David Ortiz hit a solo shot in the eighth. It was the 537th home run of his career, passing Yankees Hall of Famer Mickey Mantle for 17th on baseball’s all-time list.

Ortiz also had an RBI single off Dellin Betances (3-6) in the ninth to make it 5-3. There were still two on and two outs when Ramirez worked a 3-1 count and then sent the next pitch to straightaway center field.

It was the sixth game-ending hit of Ramirez’s career and his first for Boston, earning him an ice-water drenching in front of the dugout as the crowd celebrated.

“Our games with the Yankees are unbelievable games,” said Ortiz, the only player left on the roster from the team that rallied from a three-game deficit in the 2004 ALCS against New York and went on to win the franchise’s first World Series title in 86 years.

“This game was pretty much on their side,” Ortiz added. “It’s huge, man. Hanley is a guy that has been doing some unbelievable things. Look at the year that he’s having. Can’t ask for more than that. He’s coming in every day to do something to make things happen.”

The Red Sox moved two games ahead of Baltimore, which lost 7-6 to Tampa Bay. Instead of improving to three games back in the division, the Yankees face a five-game deficit after losing for the fourth time in five games.

“This one hurts,” Manager Joe Girardi said. “We’ve got to bounce back tomorrow. We were in a pretty good position going into the ninth inning and we weren’t able to close the deal.”

Starlin Castro had four hits and new addition Billy Butler drove in a pair of runs in his Yankees debut.

Joe Kelly (3-0) pitched into and out of a bases-loaded, one-out jam in the top of the ninth, striking out Chase Headley and then getting Mason Williams on a line drive back to the mound.

Ortiz had three RBI and three hits – two for extra bases to give him 1,186 in his career. That tied the slugger with Frank Robinson for 11th on the all-time list for extra-base hits.