Adam Wainwright pitched into the ninth inning and Yadier Molina homered, helping the St. Louis Cardinals top the Los Angeles Dodgers 5-4 on Wednesday night.

Led by Wainwright and Molina once again, St. Louis stopped a four-game slide. Tyler O’Neill also connected for the Cardinals, and Edmundo Sosa had an RBI single.

St. Louis is trying to move into position for an NL wild card.

"I thought today was a must-win game," Wainwright said. "I just felt we had to have it. We’ve got to get a split from them in my opinion."

CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM

The Dodgers dropped two games back of NL West-leading San Francisco, which rallied for a 7-4 victory at Colorado.

Wainwright (15-7) sailed into the ninth, but he was replaced by Giovanny Gallegos after Corey Seager's RBI single got the Dodgers within two. Will Smith then hit a sacrifice fly before Gallegos struck out Chris Taylor for his fifth save.

Wainwright allowed seven hits, struck out four and walked none. The 40-year-old right-hander improved to 8-1 in his last nine starts.

"That first inning I thought we started off positive and came away with one run," Dodgers manager Dave Roberts said. "Then after that, he settled in and just had really good glove-side command spinning the baseball. His curveball was sharp. This is what Wainwright does."

Max Muncy hit his 31st homer for Los Angeles, which had won three of four. Mitch White (1-3) permitted four runs and five hits in five innings.

"Pitchers come out and they give us their best and we really haven't been giving our best back at them," Muncy said. "It's just one of those things where we have the talent and we're just not putting it together. We haven't really been able to do it all year."

Seager doubled home Muncy to put the Dodgers in front in the first, but the Cardinals responded with three runs in the bottom half.

Tommy Edman singled and scored on Nolan Arenado's groundout. The 39-year-old Molina then hit a two-run drive to left for his 10th homer.

"Never ever surprised when he hits a homer," Wainwright said. "He's got so many big hits and big home runs for us over the years, of course it was Yadi."

St. Louis added another run in the fourth. Molina singled, advanced to second on Taylor's error in left and moved to third on a wild pitch. He then came home on Sosa's hit, giving the Cardinals a 4-1 lead.

Muncy connected in the fifth. Wainwright had gone a major league-leading 50 consecutive innings without allowing a home run.

DALY DOUBLE

Golfer John Daly was in attendance with the team giving away his bobblehead doll to fans who purchased a special theme ticket. The longtime Cardinals fan is participating in a PGA Tour Champions event in suburban St. Louis.

STREAKING

Trea Turner reached on an infield single in the ninth against Wainwright, extending his hitting streak to 15 games. It is the longest streak for a Dodgers hitter this season.

TRAINER’S ROOM

Dodgers: LHP Clayton Kershaw (left elbow inflammation) threw three innings in a rehab start for Triple-A Oklahoma City. The plan is for the three-time NL Cy Young Award winner to come off the injured list to start Monday against Arizona.

Cardinals: RHP Dakota Hudson (right elbow) threw 46 pitches in four innings in a rehab start for Double-A Springfield.

UP NEXT:

The Dodgers will activate RHP Tony Gonsolin (2-1, 2.78 ERA) off the injured list to start Thursday after Roberts decided to push the rest of the starting rotation back a day. The Cardinals will start RHP Jake Woodford (2-3, 4.47 ERA) after he tossed 5 1/3 shutout innings in relief Saturday in Milwaukee.