ST. LOUIS — Jake Elmore felt helpless in the top of the eighth. It just got worse for the Milwaukee Brewers in the bottom of the frame.

Milwaukee was shut down by Adam Wainwright and the Cardinals rallied for a 5-1 victory over the Brewers on Saturday.

Stephen Piscotty drove in two runs as St. Louis won for the second straight night to move back into position for the second NL wild card, a half-game ahead of the New York Mets.

Elmore was thrown out by several steps by Grichuk when he tried to score on Scooter Gennett’s single in the eighth.

“That’s kind of a buzz kill for sure,” Elmore said. “Could have been a big inning whether I score there or whether (Ryan) Braun’s up with the bases loaded, either way we’re in a good spot.”

Elmore had trouble judging the ball off Gennett’s bat.

“He froze a little bit,” Brewers manager Craig Counsell said. “And the way the ball was hit Grichuk was really shallow when he threw the ball. It wasn’t a close play.”

Wainwright then intentionally walked Braun to load the bases for Hernan Perez, who struck out looking. Perez was ejected by home plate umpire Carlos Torres when he tossed his helmet and bat and voiced his displeasure with the call.

After the ejection, Perez ran to the plate and made a kicking motion near the batter’s box indicating where he thought the pitch was.

“I haven’t seen it,” Counsell said. “Hernan doesn’t argue very often. I’m guessing it was outside.”

In the bottom of the eighth, Grichuk’s double helped clear the way for a five-run rally. Matt Adams drove in the tying run with a grounder to second and Grichuk scored on Kolten Wong’s single, giving St. Louis a 2-1 lead.

The rally spoiled another strong start for Milwaukee right-hander Chase Anderson, who allowed three hits and walked two in 5 2/3 innings. He was coming off five shutout innings against Pittsburgh last Sunday.

Carlos Torres followed Anderson with 1 1/3 scoreless innings, but Corey Knebel (1-3) and Jhan Marinez faltered in the eighth. After Wong’s single, Piscotty doubled home two more runs and Yadier Molina added an RBI single.

Knebel has struggled recently, mainly against St. Louis.

“It’s been with the Cardinals hitters certainly, but it comes down to making pitches,” Counsell said. “The ball to Grichuk got the heart of the plate.”

Keon Broxton’s 429-foot homer in the fifth gave Milwaukee a 1-0 lead. The Brewers have homered in eight straight games.

“It’s all about getting a good position to hit,” Broxton said. “I’ve found a pretty solid foundation to hitting and it’s all about seeing the ball and squaring it up.”

Wainwright (11-8) struck out seven in eight innings in his most impressive outing since he shut out San Diego on July 21. He was helped by double plays in the second and seventh and Grichuk’s throw in the eighth.

“It kind of had that feel in the air, and after I got that last out, Jhonny Peralta came up to me and he said we’re going to pick you up right here and then he went out and got a knock, and Grichuk got the double obviously,” Wainwright said. “They did a great job right there against a tough pitcher throwing very hard. I’ll take it for sure.”

It was Wainwright’s second straight win.

“We kind of had him on the ropes in that last inning and apparently he made the pitches to get out of it,” Counsell said. “He’s a tough customer and he’s going to compete against you.”

WEB GEMS

Wong, playing second for the Cardinals, made a whirling throw to start a 4-6-3 double play in the second inning and a diving play to throw out Jonathan Villar to end the third.

TRAINING ROOM

Cardinals: RHP Trevor Rosenthal (right shoulder inflammation) threw live batting practice. … RHP Michael Wacha (right shoulder inflammation) is expected to throw live batting practice Monday. … SS Aledmys Diaz (right thumb fracture) went 0 for 5 in Double-A Springfield’s season-ending loss to NW Arkansas.

UP NEXT

Brewers: RHP Zach Davies (10-7, 4.01 ERA) gets the ball on Sunday. He has made a team-high 14 quality starts. He is 1-0 with a 1.88 ERA in two starts against St. Louis this season.

Cardinals: RHP Luke Weaver (1-2, 3.96 ERA) pitches for St. Louis on Sunday. He has 22 strikeouts in his last three starts.