BOSTON -- A.J. Burnett kept the New York Yankees close, Russell Martin put them ahead and Mariano Rivera nailed down a satisfying victory over Boston.

Rivera struck out AL batting leader Adrian Gonzalez with the bases loaded for the final out and Martin hit a go-ahead double in the seventh that sent New York to a 4-2 victory Thursday night despite stranding 12 runners over the first six innings.

Burnett, coming off an awful August, allowed two runs and five hits in 5 1/3 innings after adjusting his delivery. Yankees manager Joe Girardi thought the changes would work.

"I just had a feeling tonight he was going to get it done," Girardi said, "and he did."

Struggling to stay in the rotation after going 1-2 with an 11.91 ERA in five starts last month, Burnett changed the position of his hands at the start of his windup.

"I've only really been working on that for three days. I've been pitching the same way for 11 years so it's a big change, but as the game went on I felt more comfortable," he said. "It all goes down to focus and conviction and that was a lot better."

The Yankees trailed 2-1 when Burnett left, then scored three times in the seventh off Alfredo Aceves (9-2) in a tense game that took 4 hours, 21 minutes.

Nick Swisher started the inning by striking out. Aceves then walked Andruw Jones and hit Jesus Montero, a top prospect making his major league debut, with a pitch. Aceves was replaced by Daniel Bard, who gave up a double to right-center by Martin, the first batter he faced. Two runners scored and Martin went to third on the throw to the plate. Pinch hitter Eric Chavez followed with an RBI single.

"Tremendous," Girardi said of Martin's hit. Bard "is one of the best relievers in the game and we were able to get some runs off him."

The Red Sox threatened in the ninth, loading the bases on walks to Jed Lowrie and Jacoby Ellsbury and a single by Marco Scutaro. But Rivera caught Gonzalez looking at a third strike and picked up his 36th save in 41 opportunities.

"We gave ourselves a chance," Boston manager Terry Francona said.