Tyler O’Neill and Lars Nootbaar hit back-to-back home runs in a five-run fifth inning to help the St. Louis Cardinals beat the Milwaukee Brewers 8-4 on Thursday night.

Nolan Arenado also drove in a pair of runs as St. Louis erased a three-run deficit to avoid a three-game sweep. The Cardinals sit 3 ½ games behind San Diego for the second National League wild-card spot.

"They threw their best arms at us," O’Neill said. "Honestly that’s what we should expect being the Cardinals, anyway. We’re in the hunt. We’re obviously looking up on the leaderboard there right now, but it’s a day-by-day thing."

CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM

Arenado started the two-out, fifth-inning rally with a run-scoring single to left off Brandon Woodruff (7-7) that plated Andrew Knizner, cutting the St. Louis deficit to 4-2.

O’Neill followed with a 450-foot, three-run homer to left field to put St. Louis ahead 5-4.

Two pitches later, Nootbaar hit his third home run of the season to right field for the Cardinals’ seventh set of back-to-back homers this season.

"Lars got a great swing and played some great ‘D’ out there, too," O’Neill said. "It’s always sick going back-to-back with the boys."

Jon Lester allowed four runs on six hits and three walks in 4 1/3 innings. He was knocked to his knees in the first inning when Christian Yelich lined a ball off his right calf, but he was able to remain in the game.

"That’s one tough Hombré, that’s a man’s man," Cardinals manager Mike Shildt said. "He went out there, didn’t make any excuses, said I’m going to figure out a way to keep pitching and did it. I’m sure it probably affected him some but we’ll probably never know the real truth."

Junior Fernández (1-0), Luis García, Génesis Cabrera, Giovanny Gallegos, and T.J. McFarland combined to pitch 4 2/3 innings of perfect relief. Fernández needed two pitches to get Lorenzo Cain to ground into a double play in the fifth inning to earn his first major league win.

"I thought it was going to be like a full inning," Fernández said about how he envisioned his first career win. "For me I got two outs and got my first ‘W’. It was amazing."

Woodruff allowed six runs on eight hits and a walk in five innings as the Brewers lost for just the second time on a season-high, 10-game road trip.

"They did some damage with two outs," Woodruff said. "When I needed to make some pitches, I just made some bad pitches."

Milwaukee scored all four of its runs in the top of the fourth inning. Manny Piña doubled to left field to score Avisaíl García and tie the game at 1. Kolten Wong later hit a two-run single and Willy Adames drove in Wong with a double to left field to expand the Milwaukee lead to 4-1.

TRAINER’S ROOM

Brewers: Placed RHP Freddy Peralta (right shoulder inflammation) on the 10-day injured list. Peralta left Wednesday night’s game after three innings with shoulder soreness. LHP Hoby Milner was recalled from Triple-A Nashville and pitched 1 2/3 innings in relief.

Cardinals: LHP Kwang Hyun Kim (left elbow inflammation) allowed a pair of solo home runs and threw 34 pitches for Triple-A Memphis in a two-inning rehabilitation start.

UP NEXT:

Cardinals: RHP Miles Mikolas (0-0, 2.25 ERA) will be activated off the injured list to make his second start of the season at home to open a three-game series against Pittsburgh on Friday night. The Pirates will start RHP Mitch Keller (3-10, 6.86 ERA)

Brewers: LHP Brett Anderson (4-6, 4.09 ERA) faces Washington Nationals LHP Patrick Corbin (6-12, 6.04 ERA) to open a six-game homestand Friday night.