After the defending World Series champion Giants put on a two-strike hitting clinic Friday night, the Braves got a few ideas.

They worked counts, put balls in play and came up with their own version of pesky play Saturday to rally for a 6-5 win over the Giants.

Sure, they got a pair of home runs from a resurgent B.J. Upton, bread-and-butter for a power-laden lineup. But the Braves mounted a two-run ninth-inning rally and walked off winners on Freddie Freeman’s bases-loaded single by beating the Giants at their own game.

Facing an 0-2 count with one out in the ninth, Andrelton Simmons put a ball in play that found daylight under third baseman Joaquin Arias’ glove. That error, coming after an Evan Gattis walk and before a Jason Heyward single, helped the Braves load the bases on Giants closer Sergio Romo.

Justin Upton coaxed a bases-loaded walk on a 3-2 slider that was maybe an inch or two inside, and Freeman followed with his second walk-off hit of the season.

“We really had some good at-bats throughout the whole game and then that last inning there,” Braves manager Fredi Gonzalez said. “We’ve been talking about putting the ball in play, things happen, with two strikes. And you felt pretty good with Justin at the plate and Freeman behind him, that we were going to get it done.”

A crowd of 47,178, the second of 45,000-plus to take in this weekend series, got to celebrate as the Braves snapped a four-game losing streak and watched Simmons pound dirt down Freeman’s back in the middle of an infield scrum.

“In San Diego we came back in the ninth a couple times; we just fell a little short,” Freeman said. “Today we were able to come out on top.”

The Braves, who struck out 12 times Friday night, including 10 against starter Madison Bumgarner, didn’t strike out until the sixth inning against Chad Gaudin and only three times in all.

B.J. Upton was the one making the most solid contact. He had his first multihomer game as a Brave, stole a base, and scored three runs.

He launched a fastball 450 feet to left field to give the Braves a 1-0 lead in the second inning. Four innings later, he sent a two-run shot the opposite way to pull the Braves within 5-4. Both home runs were on fastballs, something Upton struggled to catch up to much of the first two months.

“I’m just on time,” Upton said. “That’s it. I haven’t really changed anything. I just got my timing and balanced. You can hit when you’ve got those.”

It was the sixth multihomer game of Upton’s career and first since his monster 12-homer September with Tampa Bay last year. Upton is hitting .250 (10-for-40) with four home runs and seven RBIs in June, which is after he hit a majors’ worst .145 with only four home runs and eight RBIs through April and May.

Upton, Simmons and third baseman Chris Johnson all had mishaps on defense that helped the Giants score five runs in six innings (four earned) on Mike Minor, the most runs he has given up since his last loss, April 28 in Detroit. But by stranding runners in both the fifth and sixth innings Minor kept the Braves in the game. Anthony Varvaro, Luis Avilan and Craig Kimbrel shut it down from there.

The Braves won for the eight consecutive time with Minor on the mound.

“He’s been terrific doing that, minimizing damage, or don’t let the inning get away from him,” Gonzalez said. “You see a young man that’s becoming, or has (become), a major league pitcher.”