SAN FRANCISCO (AP) -- The San Francisco Giants have raced to the best record in the majors with few contributions from two of their biggest stars.
Buster Posey and Matt Cain started to change that Friday night.
Posey hit a tiebreaking two-run homer in the eighth inning for his first long ball in more than a month, Cain made a successful return from the disabled list and the Giants won for the eighth time in 10 games by beating the New York Mets 4-2.
"He's a talented hitter," manager Bruce Bochy said of Posey. "We all have our ups and downs. We talk about that all the time. He saw the ball well tonight."
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 and no homers since May 3.
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 to snap a 93 at-bat homer drought as the Giants (40-21) became the first team in the majors to reach 40 wins.
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.
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.
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.
Niese, a Defiance High School product, allowed two runs and five hits in seven innings, extending his streak of consecutive starts allowing three earned runs or fewer to 16 but still ended up with a no-decision.
"It's tough," he said. "You go out there and battle and you want to see the win beside your name. But it is what it is, it's part of the game. It'll come eventually. I have all the confidence in the offense we have here. They're going to put up runs."