He was a trending topic on Twitter for all the wrong reasons earlier Sunday night, but Braves second baseman Dan Uggla changed the tone of all that tweeting with one mighty swing against the Mets.

Then one inning later, the bottom fell out on Braves reliever Cory Gearrin.

After Uggla hit a two-run homer for the lead in the seventh inning, the Mets scored three runs against Gearrin in the eighth and pulled out a 4-2 win to avoid a sweep and snap the Braves’ eight-game winning streak.

Gearrin gave up four hits and hit a batter before recording his second out of the eighth. The decisive blow was a two-run single by .153-hitting Ike Davis, who had been hitless in 26 consecutive at-bats with runners in scoring position, and was being considered for a minor-league demotion.

“Those guys did a good job hitting” said Gearrin (1-1). “I went out there trying to make my pitches, and they put the bat on it and got some hits. They found some holes. I need to make better pitches and pick the guys up.”

Mets starter Shaun Marcum had a career-high 12 strikeouts with no walks in seven innings, and was pitching a three-hit shutout until Uggla’s 10th homer and third in six games.

“Just like that,” Braves manager Fredi Gonzalez said of how quickly things changed. “You felt like Marcum had us pretty much under control. He makes a mistake, we hit it out of the ballpark to put us one run up…. That eighth inning kind of unraveled on us a little bit.”

With their top setup relievers all on the disabled list, including done-for-the-year lefties Eric O’Flaherty and Jonny Venters, there might be more nights like this than Braves fans have become accustomed to in recent years.

“Who would you like me to put in?” Gonzalez said when asked about leaving in Gearrin after he gave up three hits and the tying run within the first four batters. “I mean, he’s the guy we give the ball to in that situation. He’s the guy we talked about. It just didn’t happen for him.”

The Mets snapped an eight-game home losing skid, and the Braves wasted another good outing by rookie starter Julio Teheran, who gave up five hits and one run in 6 2/3 innings, with three walks and five strikeouts.

For the Braves, it was a quick emotional swing from flat to excited after Uggla broke through against Mets starter Shawn Marcum, then to deflated after the three-run eighth.

“Marcum pretty much had our number all night,” Uggla said. “We were able to go up in the seventh. Teheran pitched a great game, but obviously they came back and put together some good at-bats and took the lead.”

Justin Turner led off the Mets’ eighth with a single off Gearrin. The sidearmer struck out David Wright, but then gave up a double to Lucas Duda and a run-scoring single to John Buck. He hit Mike Baxter with a pitch before Davis’ single through the right side gave the Mets a 4-2 lead.

“With him coming up and an opportunity to get a double play, that’s kind of my game,” Gearrin said. “I want to get a double-play ball right there. He put the bat on it and got a hit. You have to give him credit there. I’ll go back, look at it, try to figure out how to make the adjustment, and get them next time.”

Uggla, who dropped a pop-up in the first inning and struck out for the 61st time, quieted his critics with a towering home run to the second seating deck in left field, his 10th homer of the season and third in six games.

Teheran continued his impressive recent run, allowing five hits and one run in 6 2/3 innings, with three walks and five strikeouts. Duda’s leadoff homer in the fourth was the only damage done against Teheran, who has a 2.31 ERA in his past six starts, with two or fewer runs allowed in five of those games.

Justin Upton hustled to beat out an infield hit to start the Braves’ seventh inning. After Freddie Freeman struck out — he was 0-for-4 with four strikeouts — Uggla belted a 2-1 pitch for a 2-1 lead.

“We battled,” Uggla said. “Cory was battling They just happened to put some balls in the right places, you know? Can’t do anything about that. But he battled his butt off. Just didn’t go our way tonight. But we ran off eight in a row, won the series, so you’ve got to look at the positives.”

The Braves (30-19) still have a 4 1/2-game lead over second-place Washington in the National League East, tied for the largest division lead in the majors. The Braves will finish a five-game trip with a two-game interleague series at Toronto starting Monday.

Marcum was 0-5 with a 6.59 ERA and .318 opponents’ average in six starts before Sunday, and his .440 average allowed with runners in scoring position was the worst in the National League.

But for most of the night against the Braves, he looked like the Marcum who gave up only five runs and 13 hits in 20 innings of three starts against Atlanta during 2011-12. Actually, he looked better — until Uggla took him deep.

“Marcum changes speeds and locates so well,” Uggla said. “He knows how to pitch. He’s messing with the runners and he’ll get you into hitters’ counts and speed you up, get you to chase something. He’s a really smart pitcher, and he just really wasn’t making any mistakes. Working both sides of the plate, and keeping the ball down.”

Andrelton Simmons led off the first inning with a single, and the Braves didn’t get another hit until Simmons’ two-out double in the sixth inning. Marcum retired 13 consecutive batters before giving up the second hit to Simmons, who reached out for a low-and-away pitch and poked it into left field.

Simmons hustled to turn that hit into a double, but Jason Heyward struck out to end the inning and give Marcum his first double-digit strikeout game since 2010.

The Braves strike out more than any other NL team and have put up huge whiff totals against hard-throwing pitchers this season, including Detroit’s Anibal Sanchez (17 strikeouts). But for most of the night Marcum carved up the Braves gently with an assortment of off-speed pitches, exploiting a generous strike zone and using both sides of the plate.

The Braves had an early scoring opportunity after Uggla was hit by a pitch one out in the second inning. He advanced to second on a two-out throwing error, B.J. Upton struck out to end the inning, dropping his majors-worst average with runners in scoring position to .067 (2-for-30).