SAN FRANCISCO — Carlos Gomez lost his grip on the bat not once or twice but three times Tuesday night, sending two of them into the stands.

Given that he also hit a timely home run off Matt Cain in Milwaukee's 3-1 victory over the San Francisco Giants, Gomez became unpopular in a hurry with the 41,426 in the sellout crowd at AT&T Park.

So, he tried to make amends — by blowing a kiss.

"'The best I can do is give you a little kiss,'" he recalled saying, "and they were like screaming."

Gomez homered and Wily Peralta outdueled Cain to end a three-start winless stretch for the Brewers.

Gomez hit his 18th homer in the second as the Brewers jumped on Cain (7-7) early. Jonathan Lucroy added a ninth-inning sacrifice fly.

Aside from the slippery bat, Gomez didn't seem affected by a switch in his equipment.

"It's a little cold and they don't have the pine tar I like, the pine tar that I have a good grip with," he said. "And I used a maple bat. I don't use a lot of maple bats. I always use ash. Ash has better grip. But I feel like my ash bat is a little heavy and I swing a light bat today. Always slipping. I was scared. Those fans started getting crazy."

Cain was handed his first loss since the All-Star break. The right-hander had been 2-0 with a 1.80 ERA in the second half, and certainly would have left with a win in this one if the Giants had made good on even one of their missed opportunities.

Brandon Crawford doubled to start the eighth but the Giants failed to bring him home for what would have been the tying run.

Peralta (8-11) struck out six of nine batters during an early sequence and finished with six Ks in 6 1-3 innings for his first career victory against the Giants.

"I needed an outing like that. I was struggling the last two," Peralta said. "I've been more comfortable because I've been working in the bullpen and I've been throwing (off-speed pitches) for a strike when I need to."

Cain allowed two runs and four hits in seven innings, struck out six and didn't walk a batter for the fifth time this year — but it wasn't enough with little help from a stagnant offense.

The struggling defending World Series champions are 2 for 22 (.090) with runners in scoring position in the first two games of the series. Pinch-hitter Joaquin Arias drove in a run on a groundout in the seventh as San Francisco avoided being shut out.

"It's hard to explain when you go through something like this," manager Bruce Bochy said. "Watching tonight, we had trouble catching up with the fastball. It's been a recent trend. The bats look a little slow."

Arias' fielding error in the ninth led to Milwaukee scoring an unearned run on Lucroy's sac fly. The Giants had gone four games without an error, but still have 80 for the second-most in the NL behind the Brewers.

In the fourth, Norichika Aoki doubled leading off the inning and advanced on Jean Segura's groundout. With Aoki well off third, catcher Buster Posey threw to try to get him.

But the throw sailed wildly into shallow left field past third baseman Pablo Sandoval, who wasn't close despite lunging to his left and Aoki scored.

Peralta had lost his previous two starts and was winless in three outings since back-to-back victories July 9 and 14. He received a no-decision in his only other matchup with San Francisco, a 10-8 Brewers win April 16 at Miller Park.

Jim Henderson pitched the ninth for his 16th save in 19 chances.

"Wily certainly is a guy we'd love to have in the rotation," manager Ron Roenicke said. "Henderson at the back end, wherever we decided, whether it's closing or eighth, we think he's really going to be a valuable guy to have."

Not to mention the guy they get back Wednesday night.

Right-hander Marco Estrada returns to the mound for the Brewers for his first start since June 3 after spending time on the disabled list with a left hamstring strain.

Posey, last season's NL MVP and batting champion, was hit by a pitch from Peralta above his left elbow with two out in the sixth, and Posey grimaced in pain as he slowly walked to first.

"It's frustrating. All of us take a lot of pride to be in those situations and come through," Posey said of the missed chances.

NOTES: Peralta singled to start the sixth for his seventh career hit and sixth this year. ... Gomez is batting .444 (8 for 18) with two home runs and three RBIs against the Giants. But he had been hitless in his last 18 at-bats coming into Tuesday's game.