Jarrett Parker hit a go-ahead two-run double on a checked swing in the seventh, Buster Posey hit a sacrifice fly, and San Francisco beat the contending Brewers 4-2 on Wednesday.

"Obviously these two losses here hurt. Those are both games that we are right in," said Stephen Vogt, who had his first career pinch-hit home run in the ninth for Milwaukee. "Obviously you're going in to play the best team in baseball. That's also a good opportunity for us to go show them what we can do. You've got to look at it as a fun challenge and not an uphill battle."

The Brewers began the day 2 1/2 games behind the first-place Cubs in the NL Central, having won six of seven games before arriving at AT&T Park.

The Brewers took a 1-0 lead in the first on Travis Shaw's RBI double after Domingo Santana hit a one-out double two batters earlier.

The Giants then loaded the bases in the bottom half with no outs on a leadoff double by Gorkys Hernandez, Kelby Tomlinson's single and a walk to Parker. Posey followed with a fly to left to tie it.

Hernandez doubled again leading off the third then was hit by losing pitcher Jacob Barnes (3-4) in the midsection during the seventh and flipped his bat in disgust after nearly being plunked in the fifth, when he struck out.

On Sunday, Posey took issue with Phillies closer Hector Neris and accused the reliever of hitting him on purpose -- prompting San Francisco skipper Bruce Bochy to call the Philadelphia pitcher an "idiot."

Of Parker's decisive hit, Bochy said, "I don't think that was the swing he was looking for on the first pitch but that's a break for us, we'll take it."

San Francisco lefty Matt Moore struck out six and walked two with five hits and a run in six innings of his first career appearance against Milwaukee. His last time out, Moore snapped a nine-start winless stretch during which he was 0-5 since a June 20 win at Atlanta.

Milwaukee starter Matt Garza struck out six over five innings, allowing one run and five hits with two walks but left without a decision in a tie game.

The Brewers did little to support him, stranding runners on second and third in the sixth.

"We just didn't do enough today," manager Craig Counsell said.

ERRORS

Ryder Jones' missed catch at first base on a pickoff attempt in the seventh allowed Manny Pina to advance to second and gave the Giants an error in their sixth straight game and 11 in the last 11.

TRAINER'S ROOM

Brewers: 3B Shaw fouled a ball off his right foot in the ninth and went down in pain but stayed in and drew a walk. He will have an X-ray. ... LHP Brent Suter threw his first bullpen session since going on the disabled list Aug. 13 with a strained rotator cuff in his pitching shoulder.

Giants: RF Hunter Pence sat out a day after he was a late scratch with a tight left hamstring. ... RHP Johnny Cueto (flexor tendon strain) felt fine after he threw 47 pitches in three scoreless innings of rehab start Tuesday for Triple-A Sacramento. Bochy expects him to pitch once more in the minors before rejoining the Giants rotation. ... 2B Joe Panik, working back from a concussion, was set to play for Class-A San Jose at Visalia on Wednesday after he also played for Sacramento on Tuesday. It's unclear when Panik will rejoin San Francisco. ... 1B Brandon Belt (concussion) is doing cardio work but Bochy figures he is still two or three weeks away from being fully healthy.

"Well, it's historic," Counsell said of Los Angeles. "They're on a historic pace so you certainly respect that. There's not many teams saying they beat them. That's the bottom line. ... I'm looking forward to it. It's definitely a challenge. It comes at an important time in the season. And look, let's face it, the ultimate goal probably goes through L.A. at some point."

Giants: LHP Ty Blach (8-9, 4.59) pitches the series opener Friday at Arizona -- his first career start vs. the Diamondbacks.