SAN FRANCISCO — Their big bats stymied by spacious AT&T Park, the Milwaukee Brewers got two big defensive plays late and a key two-out swing from Travis Shaw to gain ground in the NL wild-card race.

Manager Craig Counsell even got to celebrate his 200th career win along the way.

Shaw hit a two-out double in the seventh inning to drive in Neil Walker with the go-ahead run and the Brewers held on to beat the San Francisco Giants 4-3 on Tuesday night.

"That's huge, especially after last night and everything," said Eric Thames, who narrowly missed a home run with his 433-foot triple off the brick facade in right-centre in the third. "Huge. Hopefully we can take away another series."

The win pulled Milwaukee within three games of Colorado for the second NL wild card.

"We're chasing," Counsell said, "and we need to keep pace."

Ryan Braun and Keon Broxton drove in runs while Walker and Eric Sogard had two hits apiece to help the Brewers snap a five-game losing streak to the Giants.

Milwaukee trailed 3-2 following Brandon Crawford's two-run home run in the fifth before scoring twice off San Francisco reliever Albert Suarez (0-3).

Thames drew a one-out walk and took third on Walker's double. Braun hit a tying sacrifice fly before Shaw lined a double just inside the first-base line to drive in Walker and give the Brewers the lead.

San Francisco missed a chance to tie the game when Milwaukee right fielder Hernan Perez threw out Nick Hundley sliding at the plate trying to score from second on Denard Span's single. The Giants also got a leadoff single in the ninth, but Kelby Tomlinson was thrown out trying to steal second.

"I always prepare for that situation," said Perez, a defensive replacement in the seventh inning. "I was ready. I knew they were going to send him. That was the tying run and (Buster) Posey was on deck. That was the situation to send him."

"Good defence in this park is important," Counsell said. "They're a team that puts the ball in play a ton and that means defence is going to be important."

Pablo Sandoval had two hits and Posey singled and scored twice for the Giants.

Jeremy Jeffress (1-0) retired three batters to get the win, his first in the National League after being acquired in a trade from Texas at the deadline. Corey Knebel pitched the ninth for his 27th save.

The Brewers scored on Broxton's RBI single in the first and tacked on an unearned run in the fourth when Gorkys Hernandez dropped Broxton's two-out fly ball at the warning track in right field.

San Francisco twice left the bases loaded before Crawford hit his 11th home run this season off Brewers starter Jimmy Nelson.

COUNSELL'S MILESTONE

Counsell seemed unaware that he had reached the 200-win plateau and was even less impressed by the achievement. "A win in 2017, in the spot we're in, means more for sure," Counsell said.

SAMARDZIJA'S STREAK ENDS

Giants starter Jeff Samardzija had an uneven outing that ended his three-start winning streak at AT&T Park. Samardzija allowed one earned run over six innings but allowed six hits and repeatedly pitched out of trouble. The right-hander credited his fastball and an improving curveball.

"For me that curveball's been a big pitch lately," Samardzija said. "When it's been there I've pitched late into games and had success. When it hasn't I've had to work a little harder with my fastball, probably threw a lot more pitches and innings than I should have."

TRAINER'S ROOM

Giants: Hernandez was in the lineup after Hunter Pence was a late scratch because of a tight hamstring. Pence drew a walk as a pinch-hitter in the eighth and was replaced by a pinch-runner. ... RHP Johnny Cueto threw 47 pitches over three scoreless innings of rehab start with Triple-A Sacramento. Cueto allowed three hits with one strikeout. 2B Joe Panik went 0 for 2 with a strikeout and played five innings in the same game.

UP NEXT

RHP Matt Garza (6-7 4.81 ERA) makes his fifth career start against the Giants in the Wednesday afternoon series finale while San Francisco will go with LHP Matt Moore (4-12, 5.54 ERA).

___

More AP baseball: https://apnews.com/tag/MLBbaseball