SAN FRANCISCO -- For the first time in his 14-year career, Jeremy Affeldt earned a win on his birthday.

But he said the real gift was watching Matt Cain return to form. The Giants starter came off the disabled list to carry a no-hitter into the sixth inning before settling for a no-decision in Friday's 4-2 victory over the New York Mets.

"We've been playing so well, and he hasn't even pitched much," Affeldt said. "Now you add him to the mix and he throws like he did tonight? To take 15 days off and come back and act like you haven't been off at all?"

Buster Posey put a bow on things with a tiebreaking two-run homer in the eighth inning -- his first home run since May 3 -- to provide a rousing start to a 10-game homestand at AT&T Park. The homer made a winner of Affeldt, who pitched the eighth inning on the day he turned 35.

The win improved the Giants' record to a major league best 40-21. They are the first big-league team to reach 40 victories, a distinction they hadn't held since 1973, according to Elias Sports.

The Giants remain 81/2 games up in the National League West, a lead built largely without contributions from Cain, who hadn't pitched since May 21 because of a right hamstring strain. He also went on the D.L. earlier this season because of a cut on his right index finger.

Cain -- and his fastball -- looked as healthy as ever Friday as he touched 94 mph on the stadium radar gun. Posey recognized early that there was no need to get fancy. They simply worked the electric fastball to both sides of the plate.

"His fastball had as much life on it as I've seen in a while," Posey said. "The encouraging thing was that the off-speed stuff wasn't even as sharp as it can be."

Cain didn't allow a base runner until walking Curtis Granderson to lead off the fifth. The first hit came on Ruben Tejada's infield single in the sixth, a ground ball deep in the hole at shortstop where Brandon Crawford didn't have a chance to throw out the runner.

The real damage didn't come until the seventh, when the Mets' had two big hits -- both on sliders. Cain said that Matt den Dekker hit a good one for a double and that Daniel Murphy hit a bad one for a two-run homer. "It just kind of rolled in there," Cain said of the fateful pitch.

Murphy's blow gave the Mets a 2-1 lead. But it was short-lived, as Crawford drove home Brandon Hicks with a two-out single in the bottom of the seventh. Such contributions from the bottom of the lineup are why Cain ranks this offense with those from the Giants' recent World Series years.

"It's up there," he said. "These guys can hit from top to bottom. It's not always the guys in the middle of the lineup that are going to hurt you with power. The rest of the guys can do it, too."

In the end, though, it was a guy from the middle of the lineup who finished the job. Posey, who had gone 93 at-bats without a long ball, crushed a one-out home run off Carlos Torres to break a 2-2 tie.

Posey entered the night 11 for his past 63 (.175). But he went 3 for 4 this time and hit his first homer at AT&T Park since April 29.

"I think he's been getting good swings off," manager Bruce Bochy said. "The home runs haven't been there, but he's hitting it hard. He just hasn't gotten the ball up in the air. Tonight he did."

  • To make room on the roster for Cain, the Giants designated reliever David Huff for assignment. The left-hander was 1-0 with a 6.30 ERA over 16 games this season.

    As he exited the clubhouse, Huff said he was surprised to get the news. Still, he called his time with the Giants "a great ride" and said he would accept a minor league assignment if he clears waivers.

  • Dylan Davis, a center fielder from Oregon State, highlighted the Giants' selections on day two of the first-year player draft. The Giants took the 6-foot, 215-pounder in the third-round (87th overall). Davis led the Pac-12 Conference with 64 RBI.

    The Giants also took a Stanford outfielder, Austin Slater, in the eighth round (238th overall). In all, eight of the Giants first 10 draft picks have come from the college ranks.

    Follow Daniel Brown on Twitter at twitter.com/mercbrownie.

    SATURDAY'S GAME
    N.Y. Mets (Bartolo Colon 5-5)
    at Giants (Tim Hudson 6-2)
    7:05 p.m., CSNBA

    Online extra
    Scan this code with a smartphone to view a Giants photo gallery or go to http://photos.mercurynews.com.