SAN FRANCISCO (AP) - Buster Posey hit a tiebreaking two-run homer in the eighth inning and the San Francisco Giants won for the eighth time in 10 games by beating the New York Mets 4-2 on Friday night.
The big blast off Carlos Torres (2-3) capped a three-hit day for Posey, who entered the game with only four hits in his past 42 at-bats at home.
Angel Pagan started the rally with a leadoff walk against Torres and advanced to second on a groundout. Posey followed with a long drive to left-center for his eighth homer and just his 12th extra-base hit of the season as the Giants (40-21) became the first team in the majors to reach 40 wins.
Daniel Murphy hit a two-run homer for the Mets, who lost their fourth straight game. The bullpen has taken all four of the losses and has a major league-worst 15 losses on the season.
Jeremy Affeldt (1-1) pitched a scoreless eighth on his 35th birthday to get the win. Sergio Romo got three outs for his 19th save in 21 chances.
Matt Cain allowed two runs and three hits in seven innings in his first start back from a stint on the disabled list for a strained right hamstring. But he got a no-decision and still has only one win in nine starts in a rough season that has included two trips to the disabled list.
Cain was in complete control with a 1-0 lead having faced the minimum 18 batters through six innings before the Mets quickly turned the tide in the seventh.
Matt den Dekker led off the inning with a double for New York's second hit of the game and Murphy followed with his fourth home run of the season to put the Mets ahead 2-1.
The Giants tied it in the bottom half when Brandon Hicks and Brandon Crawford teamed up again to produce a run. Hicks drew a two-out walk from Jonathon Niese, advanced to second on a wild pitch and scored on Crawford's single to center.
The duo produced San Francisco's first run in the fifth when Hicks tripled and scored on Crawford's sacrifice fly to make it 1-0.
Niese allowed two runs and five hits in seven innings, extending his streak of consecutive starts allowing three earned runs or fewer to 16.
Cain retired the first 12 batters of the game before walking Curtis Granderson to lead off the fifth. Granderson was quickly erased when Andrew Brown hit into a double play.
The Mets got the leadoff runner on again in the sixth when Ruben Tejada reached on an infield single, beating Crawford's throw from the hole at shortstop for New York's first hit of the game. Cain once again followed that by inducing a double-play grounder by Travis d'Arnaud.