PHOENIX (AP) Arizona had ample reasons to be a beaten-down ballclub one day after being officially eliminated from the National League playoff race.

Instead, the Diamondbacks powered through 19 innings of baseball, used 13 pitchers and earned an unlikely 3-2 win over the St. Louis Cardinals in a game that lasted nearly seven hours.

Ildemaro Vargas had a game-tying, pinch-hit homer in the ninth inning on Tuesday and then singled with the bases loaded in the 19th at 1:34 a.m. local time on Wednesday, sending Arizona's players streaming from the dugout in celebration.

"We just didn't shut down," Arizona manager Torey Lovullo said. "We had plenty of opportunities to feel sorry for ourselves and we didn't. We scratched together some runs at the right time."

Then it was Vargas' turn to be the hero again, smacking a single - his fourth hit of the game - through the left side of the infield. He raised his hands as players rushed the field.

"I was so excited, just pumped up," Vargas said through an interpreter.

If Vargas hadn't come through with the game-winning hit, he was going to be on the mound in the 20th inning because the D-backs were out of available pitchers.

"We didn't have much to go on - that was it," Lovullo said. "Luckily, we didn't have to find out how that looked."

The game last 6 hours and 53 minutes and featured 24 pitchers and 48 strikeouts, with both teams plowing through bullpen arms thanks to September's expanded rosters. The Diamondbacks used a franchise-record 30 players. It was the longest game by innings and time in Chase Field history.

With the Rockies beating the Giants in 16 innings earlier, it marked the first time since June 8, 2013 - Mets-Marlins and Blue Jays-Rangers - more than one game went at least 15 innings the same day, according to MLB Stats.

These two teams were set to play again in Phoenix 11 hours later.

It's a particularly tough turnaround for the Cardinals, who are locked in a playoff race with the Milwaukee Brewers. St. Louis had its lead in the NL Central cut to 2 1/2 games over Milwaukee. The Cardinals have four games remaining and the Brewers have five.

The Cardinals' bullpen blew two one-run leads, once in the ninth inning and again in the 13th as they wasted a stellar outing from starter Jack Flaherty.

St. Louis manager Mike Shildt said the team's confidence wouldn't be shaken.

"We're in a good spot," Shildt said. "We're playing good baseball. Played good baseball tonight. Played clean. 19 innings and no errors. Played the game well. Just came up short.

Paul Goldschmidt looked like he'd be the hero after giving the Cardinals a 2-1 lead in the 13th when he hit a homer for the second straight night in his return to Chase Field. The six-time All-Star spent his first eight seasons with the Diamondbacks before being traded to St. Louis last offseason.

Turns out, there was much more baseball left to play.

Ahmed started the D-backs' 13th inning rally with a triple and then Dyson drew a walk off John Gant. Pinch-hitter Caleb Joseph ripped a single through the right side of the infield to tie the score at 2-2, but the rally stalled when Walker hit into a double play and Vargas grounded out.

Several hours before the game's conclusion, Flaherty continued his run of outstanding pitching with seven brilliant innings, including a no-hitter through six, but Andrew Miller couldn't hold a 1-0 lead in the ninth.

With one out, Vargas stunned the Cardinals with a solo shot that just cleared the fence in right-center field and tied the game. Miller retired the next two batters.

The Diamondbacks looked like they might rally in the 11th when Tim Locastro hit a one-out single. With two outs, Vargas hit a high chopper for an infield single but Locastro was thrown out at third when he barely slid past the bag while trying to take an extra base.

Flaherty, who finished with 11 strikeouts, has been brilliant for the Cardinals as they've charged to the top of the division. The right-hander has a 0.97 ERA during the second half of the season and has given up just seven earned runs over the past two months.

Dexter Fowler provided the Cardinals' early offense, leading off the game with a solo homer to right field. It was Fowler's 18th homer of the season, and 26th leadoff homer of his career.

LET'S GET HYPE

By the 15th inning, the D-backs' and Cardinals' benches appeared to be having a good-natured contest to see who could be the most raucous and obnoxious when cheering. It was easily heard because most of the Chase Field crowd was gone.

WEIRD NO-HIT ENDING

Flaherty's no-hitter ended on a strange play when a hard ground ball from Eduardo Escobar hit the seam between the dirt and grass and bounced behind Paul Goldschmidt, who tried to reach back with his bare hand, but couldn't make the play.

"It was hooking toward the line," Goldschmidt said. "It hit the lip on the turf and bounced back the other way. Tried to grab it with my bare hand. Weird."

UP NEXT

Cardinals: RHP Michael Wacha (6-7, 4.68 ERA) allowed one run over four innings and in his previous outing against the Chicago Cubs.

Diamondbacks: RHP Merrill Kelly (12-14, 4.31) will head to the mound to begin a game that starts at 12:40 p.m. local time. He'll bring a 15-inning scoreless streak into the game.