NEW YORK (AP) -- Alex Rodriguez set a major league record with his 24th career grand slam, passing Lou Gehrig with a tiebreaking shot in the seventh inning that sent the New York Yankees to a 5-1 victory over the San Francisco Giants on Friday night.
Rodriguez's slam helped CC Sabathia (14-13) beat Tim Lincecum in a matchup of former Cy Young Award winners having subpar seasons.
More importantly for the Yankees, it led them to their second win in seven games as they cling to faint playoff hopes. New York began the day 3 1/2 games behind Tampa Bay and Texas for the second AL wild card, with three other teams in between.
Alfonso Soriano also homered and New York opened its final homestand of the season with a much-needed victory, hours after pitcher Andy Pettitte announced his plans to retire -- again -- following this season.
The news about Pettitte hardly came as a surprise, but the 41-year-old lefty put to rest any speculation he might be back next season. Pettitte, who stepped off the mound for a year before returning in 2012, is scheduled to start the series finale Sunday -- the same day the Yankees will honor retiring closer Mariano Rivera in a pregame ceremony.
Hometown rookie Juan Perez hit an RBI double for the Giants, who have spent all week in New York. The defending World Series champions took two of three from the Mets at Citi Field, where a large throng of vocal San Francisco fans made them feel right at home.
Giants rooters came out in the Bronx, too, easy to spot in their orange or black jerseys. An audible chant of "Let's go Giants!" quickly drew boos from Yankees fans in the crowd of 41,734.
Plenty were surely there to see Perez, who went to high school in the Bronx and is having a big week in his first trip home as a major leaguer. He went 3 for 3 with an RBI single in Thursday's 2-1 victory over the Mets, then doubled his first two times up Friday -- including one off the left-field fence.
Perez said he left 12 tickets for family and friends, but plenty of others bought their own. His father was unable to attend Thursday's game because he was working, but Perez expected him in the stands at Yankee Stadium.
With the score tied at 1, Eduardo Nunez grounded a single through the right side to start the seventh. Lincecum (10-14) hit Brendan Ryan with a pitch and walked Ichiro Suzuki with two outs, loading the bases and ending the right-hander's night.
Rodriguez, hampered by a sore leg lately, reached out and lofted a 2-1 pitch from George Kontos toward the hitter-friendly dimensions in right field for his 654th career homer and seventh this season.
The hit snapped a 1-for-25 slide for A-Rod, who returned Aug. 5 from hip surgery. It was his 14th slam for the Yankees, moving him ahead of Joe DiMaggio for second place on the franchise list behind Gehrig.
Sabathia was pulled after a leadoff single in the eighth and walked off to a warm ovation. David Robertson got Perez to ground into a double play, and Rivera worked a perfect ninth.
Lincecum, who had won four straight decisions, was looking for his first five-game winning streak since early in the 2010 season. He was charged with four runs and five hits in 6 2-3 innings. He threw 66 of 121 pitches for strikes.
NOTES: Giants CF Angel Pagan was rested in favor of Perez. San Francisco manager Bruce Bochy said he expects Pagan to be able to start in center on Saturday. Pagan had left hamstring surgery this season and missed 82 games. ... DH Buster Posey singled in the sixth to end a 1-for-23 skid on the road trip. Bochy said Posey will catch the remaining two games in the series. ... Bochy said it was his first trip to the new Yankee Stadium and he planned to get out to Monument Park later in the series. ... Looking to spark his struggling lineup, Yankees manager Joe Girardi moved a slumping Suzuki into the leadoff spot, partly because he had faced Lincecum several times in the past few years. ... LHP Boone Logan (elbow) was available, Girardi said. ... After the Yankees got in late following Thursday night's loss at Toronto, C Chris Stewart was rested in favor of rookie J.R. Murphy. "Physically, I just think it's too hard," Girardi said.