BOSTON (Reuters) - The New York Yankees rallied from behind and held on through a tense ninth inning for a 4-2 win over the Boston Red Sox on Thursday to keep the heat on their bitter rivals in the American League East.

Alfredo Aceves pitched himself into trouble in the seventh, issuing a walk to Andruw Jones and hitting Jesus Montero with a pitch before Martin brought both runners home.

"I got in a situation where he didn't want to walk me, so he threw me a strike," said Martin. "He threw me a fastball up and over, and I put a good swing on it."

The Red Sox raised the home crowd's hopes by loading the bases against Mariano Rivera, but the Yankees reliever struck out the American League's leading hitter Adrian Gonzalez to slam the door shut.

Dustin Pedroia scored for the Red Sox, bashing a two-run homer in the fourth inning to erase a 1-0 Yankees lead.

New York attacked Red Sox starter Jon Lester who gave up seven hits and three walks in five innings but showed grit to strand nine Yankees' runners and allow just one run.

"That was the theme tonight, just hanging in there, minimizing damage. I ended up making pitches when I had to," Lester said. "Really, two hard-hit balls and 114 pitches later, I could only get through five (innings)."

Five Yankees relievers combined to pitch 3-2/3 scoreless innings in relief of starter A.J. Burnett. Apart from the Pedroia home run, Burnett pitched well for five hits and two walks while striking out four. Cory Wade picked up the win and Rivera collected his 36th save.

New York first baseman Mark Teixeira left the game after being hit on the right knee by a pitch from Aceves.

(Reporting by Mike Mouat in Windsor, Ontario. Editing by Ian Ransom)