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.