ATLANTA — When Mike Foltynewicz was summering in the minor leagues, it was hard to envision an October like this.

Yet there he was Friday, coming through when Atlanta needed it most.

Foltynewicz threw seven dominating innings, Adam Duvall hit a pinch-hit homer and the Braves evened the NL Division Series with a 3-0 victory over the St. Louis Cardinals in Game 2.

After spending a good chunk of his summer at Triple-A Gwinnett, Foltynewicz has been a different pitcher since returning from the minors. He went 6-1 with a 2.65 ERA over his last 10 starts — a brilliant run that carried right into the postseason.

“Pretty special,” Foltynewicz said. “I really made sure to slow things down, to stay in my mechanics and make sure all my pitches were working like they were tonight. It was smooth sailing, so it was a lot of fun.”

The best-of-five series now shifts to St. Louis, where Mike Soroka goes for the Braves in Game 3 on Sunday against Adam Wainwright.

Facing St. Louis ace Jack Flaherty, who had one of the great second halves in baseball history, Foltynewicz allowed three hits, struck out seven and walked none during an 83-pitch outing that kept the Cardinals from mounting any semblance of offense.

He only allowed one runner as far as second base — and that wasn’t even his fault. In the second, Yadier Molina singled and Braves second baseman Ozzie Albies extended the inning by misplaying Paul DeJong’s grounder for an error.

No problem. Foltynewicz fanned Harrison Bader to end the threat.

After Kolten Wong hit into a double play to wrap up the seventh, Duvall emerged from the dugout to hit for Foltynewicz in the bottom half.

Duvall was greeted by a smattering of boos from the SunTrust Park crowd that clearly wanted Foltynewicz to go at least one more inning — especially after the Braves bullpen imploded the night before in a Game 1 loss.

The heckles turned to cheers when Duvall drove a 3-2 pitch from Flaherty into the center-field seats for a two-run homer, giving the Braves a bit of breathing room.

“I heard 50,000 people let me know that they wanted Folty to stay in the game,” Duvall quipped. “I wanted to put together a good at-bat.”

Josh Donaldson drove in Atlanta’s other run with a two-out single in the first.

“I don’t look at what that other guy is doing,” Flaherty said. “It came down to really two pitches.”

An All-Star in 2018 who started two games for the Braves in last year’s playoffs, Foltynewicz was demoted to the minors in late June with a record of 2-5 and 6.37 ERA. He didn’t return until early August.

“It’s pretty cool to see for a guy that went through what he went through this year and where he’s come back from,” Braves manager Brian Snitker said.

Duvall spent nearly the entire season at Triple-A, so it wouldn’t be a stretch to say this was as much a victory for the Gwinnett Stripers as the Braves.

Max Fried, normally a starter and pitching on back-to-back days for the first time all season, breezed through the eighth before turning it over to Mark Melancon, who gave up four runs in the ninth inning of the series opener, sending the Braves to a 7-6 loss.

Melancon surrendered a pair of one-out singles, drawing groans from the crowd, but he struck out Molina and Wong to earn the second postseason save of his career.

Yet this one will be remembered for Foltynewicz outdueling Flaherty, who had surrendered three runs only one time in 15 second-half starts.

The 23-year-old right-hander went 7-2 with an 0.91 ERA after the All-Star break, a minuscule figure surpassed only by Jake Arrieta (0.75) for the 2015 Chicago Cubs and Greg Maddux (0.87) for the 1994 Braves.

Flaherty was the NL pitcher of the month for both August and September.

Foltynewicz has the upper hand in October.