Paul Goldschmidt homered twice, and the St. Louis Cardinals overcame a five-run deficit to beat the Milwaukee Brewers 8-5 Thursday and extend their longest winning streak in 39 years to 12 games.

On an early day that Adam Wainwright was struggling, St. Louis led 5-0, but rallied with one run in fifth, three in seventh and two in ninth. Cincinnati and Philadelphia were both playing later on Thursday. The Cardinals won five more games than St. Louis. They will be competing for the second NL Wild Card.

CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM

St. Louis began its winning streak by overcame a four-run deficit against Cincinnati to win on Sept. 11. The Cardinals are on their longest winning streak since April 11-24, 1982, and are two shy of the franchise record set in 1935.

Milwaukee has lost five in a row since clinching its fourth consecutive playoff berth on Sept. 18, including four defeats to the Cardinals.

Yadier Molino started the comeback by scoring an RBI run in the fifth against Adrian Houser .

St. Louis loaded the bases in seventh with two outs on Jake Cousins’s walks.

St. Goldschmidt scored a run to tie the game with a homerun.

Nolan Arenada took the ninth inning walk against Aaron Ashby (3-1). He scored on Manny Pina’s pass ball to take a 6-5 advantage. Molina also added a sacrifice fly.

Goldschmidt added his 29t homer in the ninth off Ashby.

T.J. McFarland (4-1) pitched a one-hit seventh, Luis Garcia threw the eighth and Giovanny Gallegos struck out two in a perfect ninth for his 12th save in 20 chances as four relievers combined for shutout relief.

Wainwright, who has won nine of his last 10 decisions, allowed five runs, four hits and two walks in four innings.

Tyrone Taylor scored a grand slam and took a solo pitch in the fourth.

Wainwright joined Hall of Famer Bob Gibson as the only St. Louis Cardinals’ pitchers with 2,000 strikeouts, fanning Milwaukee’s Luis Urias in the fourth inning.

The 40-year-old right-hander became the ninth active pitcher with 2,000. Gibson got his 2,000th strikeout when Pittsburgh’s Roberto Clemente was called out on July 13, 1969. Gibson, who died last October, finished with 3,117.ot.

CLICK HERE TO GET THE FOX NEWS APP

TRAINER’S ROOM

Cardinals: Arenado, who left in the fifth inning Wednesday night with lower back tightness, started at third and went 0 for 3 with a walk. Mike Shildt, Cardinals manager said Arenado received treatment for his lower back and was ready to play.

Brewers – Pina received a foul tip from Wainwright’s bat, which was on the left side of Wainwright’s left shin pad. He was able to continue the game after a brief delay. The scheduled day off was for RF Avisail Garcia, who instead of pitching in the sixth, pinch-hit for Houser and grounded out.

GET A NEW GLOVE

Before Cousins threw a pitch in the seventh, the umpires made him switch gloves. Craig Counsell, Brewers manager, came to the table.

UP NEXT

Cardinals: LHP J.A. Happ (9-8, 6. 02 ERA) opens a four-game road series as the Cardinals take on LHP Justin Steele (3-3,4. 20 ERA) and the Chicago Cubs. Happ will be facing the Cubs for the first time since 2017.. Happ is currently 1-5 and has a 6. 00 ERA in seven career starts against them, including 0-2 at Wrigley Field.

Brewers: LHP Eric Lauer (6-5, 3. 03 ERA) opens the final regular season home series against RHP Tyler Megill (3-5, 4. 57 The New York Mets. Lauer is making his debut against the Mets.