Travis Shaw collects key RBI in Milwaukee Brewers’ win in San Francisco

Milwaukee Brewers pitcher Jimmy Nelson works against the Giants during the first inning Tuesday in San Francisco. (AP photo)

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-center 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.

Milwaukee Brewers catcher Manny Pina, right, holds the ball for the home plate umpire to see after tagging out the Giants' Nick Hundley, left, during the eighth inning on Tuesday in San Francisco. (AP photo)

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.”

“Good defense in this park is important,” Counsell said. “They’re a team that puts the ball in play a ton and that means defense 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.