Freddie Freeman’s home run and Jace Peterson’s three-run triple fueled a ninth-inning rally that gave the Braves a 7-5 win against the San Francisco Giants on Sunday, stunning a sold-out crowd at AT&T Park and earning a split of a four-game series against one of baseball’s hottest teams.

It was the kind of stirring rally that Atlanta seemed almost incapable of last season regardless of the inning, and this time it was in the ninth — the first time the Braves won in 22 games this season when trailing after eight innings, and first time the Giants lost in 26 games when leading after eight.

“Like I said before, I love this ball club,” said Peterson, who followed up his career-first three-hit game in Saturday’s 8-0 win with his biggest hit Sunday. “We’ve got a lot of fight in us. We’ve got a lot of good players, and I can’t wait to get to Arizona.”

The Braves are 3-5 on a 10-game trip concludes in Arizona with a series that starts Monday. They got back to .500 at the 50-game mark Sunday, and they’ve played better than the record indicates lately, with the glaring exception of the bullpen, which has spoiled a couple of strong performances by Braves starters.

Julio Teheran settled in after giving up back-to-back homers in the second inning Sunday, and Juan Uribe hit his second two-run homer in as many days to give the Braves a 3-2 lead in the seventh against Giants ace Madison Bumgarner.

Then Atlanta’s bullpen entered the picture, and Joe Panik’s two-run homer off outmatched reliever Donnie Veal capped a three-run seventh inning for a 5-3 Giants lead. The Braves got Panik’d, but didn’t panic.

“You can say a lot of stuff about our team, that we’re short and we’ve got some deficits in certain areas,” said manager Fredi Gonzalez. “But one thing we’re not short of is fight. And willingness to not give up. These guys battle and battle. After we take the lead, the Giants take the lead again, and we didn’t give up. We had two more innings to try to get back in the game, and we did. What a great effort by the team.”

Freeman, out of the starting lineup for the first time in 218 games Sunday, entered in the bottom of the seventh for defense, then produced big offense: a home run in the ninth to pull the Braves within a run. It was his second homer in three days, both to straightaway center and both off closer Santiago Casilla, who had a 1.66 ERA before Sunday and has given up two homers to Freeman and only one against anyone else this season.

“I was just trying to get a good pitch and just try to get on base,” Freeman said. “That’s the goal right there. I was thinking I was going to take a strike, but I was hoping he thought that, too, so he was going to groove one. That’s why I went up there swinging. I was lucky to get it over the fence.”

Andrelton Simmons, who followed Freeman by drawing a walk, said the home run energized the dugout.

“It was a one-run game after that,” Simmons said. “You know you’re one swing away, so you’ve got high hopes. And it worked out great.”

Christian Bethancourt followed Simmons by hitting a grounder that shortstop Brandon Crawford botched, a crucial error on a a potential game-ending double play. Pinch-hitter A.J. Pierzynski hit a bloop single between the second baseman and right fielder to load the bases for Peterson.

The first-year Braves second baseman cleared them with a triple to the right-center gap, his second triple and third extra-base hit in two games. The best sight for the Braves in a week: Pence running frantically into the gap to chase Peterson’s hit.

“My hands were up in the air and I was jumping up and down,” Freeman said. “That was pretty cool.”

Teheran was charged with four hits, three runs and four walks in six innings Sunday, the first two runs coming on consecutive homers by Brandon Belt and Crawford in the second inning, when Teheran’s velocity was down and his location off, as it’s been far too frequently this season away from Atlanta.

He didn’t allow another base runner to reach second until Matt Duffy’s leadoff double in the seventh, after which Teheran was replaced by Veal and the inning got ugly for Atlanta.

“I didn’t feel comfortable the whole game with Julio, to tell you the truth,” Gonzalez said. “I know the numbers show a little different, but it wasn’t a normal Julio Teheran outing that you feel pretty darn good about…. Health-wise, he’s fine. But it’s not the same Julio Teheran from a year ago, where you’d give him the lead and it’s over with.”

Belt homered on 79-mph slider with the count 2-2, after fouling off three consecutive pitches – a changeup, a fastball, then a slider — and Crawford homered five pitches later on an 89-mph fastball with count 3-1.

It looked like it might be another road debacle for Teheran, who had a 7.42 ERA and .376 opponents’ average in six road starts before Sunday, compared to a 1.82 ERA and .200 opponents’ average in four home starts.

But then something clicked with Teheran, and the only batters who reached base between those homers and the end of the sixth inning did so on three walks, a fielding error by first baseman Chris Johnson, and a Belt single in the sixth. Those baserunners were scattered for the Giants, who didn’t advance a runner to second base in that span.

The Braves haven’t had a bullpen this bad in a long time. Entering Sunday, Atlanta relievers had a National League-worst 4.65 ERA, and the team’s .271 opponents’ average in the late innings of close games was also the highest in the NL.

With lefty Luis Avilan getting a rest, Gonzalez called on Veal, a journeyman who has looked overmatched in both of his major league stints this season, and certainly did Sunday, when his ERA climbed to 14.54. Veal has given up at least one run each of his six appearances this season, allowing a total of eight hits, seven runs and three homers in just 4 1/3 innings.