Stephen Piscotty scored on a throwing error in the ninth inning after Carlos Martinez struck out a career-high 13, leading the Cardinals over the Milwaukee Brewers 6-5 on Monday night.
With two on and nobody out in the ninth, Yadier Molina dropped down a bunt. Reliever Tyler Thornburg (5-5) threw to third base for a force out, but Villar's throw to first was wild, allowing Piscotty to score from second.
The Cardinals maintained a slim lead over Pittsburgh for the second NL wild card.
After Martinez held Milwaukee to one run over six innings, the Brewers scored four runs in the seventh to take a 5-3 lead. St. Louis tied it in the eighth on a two-run homer by Randal Grichuk off Corey Knebel.
Seung Hwan Oh pitched a perfect ninth for his 14th save. Miguel Socolovich (1-0) worked 1 2/3 scoreless innings to pick up his first win.
The Cardinals took the lead on a sacrifice fly by Wong in the fourth. Jedd Gyorko homered in the fifth and Kolten Wong hit a solo shot in the fifth for a 3-1 advantage.
Martinez allowed four hits and walked two while throwing 98 pitches. He struck out eight of the first 11 batters and didn't allow a hit to the outfield until the sixth.
Brewers starter Zach Davies (10-7) matched his career high with nine strikeouts but gave up three runs and seven hits over 6 1/3 innings.
Adam Wainwright (9-8, 4.67 ERA) will look to continue his career dominance of the Brewers on Tuesday. The veteran is 13-8 with a 2.23 ERA in 33 games against Milwaukee. Wily Peralta (5-9, 5.87) will make his 18th start of the season when he faces the Cardinals on Tuesday.