When they peeled five veterans off their roster at the trade deadline, the Diamondbacks were a team in freefall. Their season had been a disappointment — and nothing that happened the rest of the way figured to change that.

Instead, six weeks later, the Diamondbacks open a nine-game homestand on Monday, Sept. 15, with something few could have imagined: a chance to make the playoffs.

“If you would have told us on August 1 that with two weeks to play we’re going to have a shot, I think you’d have had a lot of guys sign up for it,” Diamondbacks right-hander Zac Gallen said. “I just said, ‘Give us meaningful baseball the last week of the season — that’s not too much to ask — and we’ll see what happens.’”

The Diamondbacks open a three-game series with the San Francisco Giants just two games out of a wild-card spot with 12 games left in the season.

That they are in this position is the result of a confluence of factors. Their starting pitching has stabilized. Their defense is much improved. Their offense has continued to produce. It has added up to a 24-17 record since the start of August.

But they have benefited from factors out of their control, as well. Namely, the play of the New York Mets, who over their past half-season worth of games have played at a 98-loss pace. It has allowed a team such as the Diamondbacks — who enter their homestand with a 75-75 record and haven’t been more than a game over .500 since June 25 — to remain a contender.

Take last week: The Diamondbacks went just 2-4 but managed to gain 2 1/2 games on the Mets, who went 0-7.

“We’re playing some good teams and winning some games,” Diamondbacks right fielder Corbin Carroll said. “But a lot of it, too, is what other teams are doing right now and kind of giving us a chance.

“At this point, we’re in it. We’re just going to keep taking it a day at a time and trying to go 1-0.”

In the week leading up to the deadline, the Diamondbacks traded right-hander Merrill Kelly, third baseman Eugenio Suarez, first baseman Josh Naylor, outfielder Randal Grichuk and reliever Shelby Miller, all of whom had been significant contributors this season.

Amazingly, the Diamondbacks haven’t missed any of them all that much, if at all.

Their defense has improved in part because of the emergence of Blaze Alexander, who has played well both at third base and in occasional games in left field and center field. Alexander, who bounces around the field and clubhouse like a puppy, has also provided a sort of infectious energy that seems to transfer to others.

“I think we got athletic,” Diamondbacks manager Torey Lovullo said. “We got very young and I think certain players gave us a certain energy and they’ve gone out there and really performed at a great level. Defensively, we got real good, and I think that helped our pitching.”

Gallen (2.83 ERA) and left-hander Eduardo Rodriguez (3.63 ERA) have been far more effective since the deadline, and right-hander Nabil Crismatt (2.70 ERA) — who signed as a minor-league free agent in the second week of August — has been a godsend since moving into the rotation, essentially giving the Diamondbacks similar results as Kelly.

The club still has questions, most of them centered on the bullpen. A problem spot throughout the season, it remains unreliable. The upcoming schedule is not forgiving.

The Diamondbacks have four series left, all of them against contending clubs: the Giants, Philadelphia Phillies, Los Angeles Dodgers and San Diego Padres. They won’t face either of the Giants’ top two starters (Logan Webb and Robbie Ray), nor are they lined up to face the Phillies’ top arms (Cristopher Sanchez and Ranger Suarez).

The Diamondbacks believe something else might be working in their favor, something reminiscent of their run to the World Series in 2023. Back then, after backing into the playoffs, the Diamondbacks spoke openly about how little pressure they felt in October given the absence of expectation.

Several players said over the weekend the same phenomenon might be in effect following the trade deadline sell-off.

“This is very reminiscent of 2023 of just we’re not really supposed to be the team that makes the push that we did and we kind of wore that with pride of being the underdogs,” reliever Ryan Thompson said. “I feel like maybe some of the pressure was lifted on all sides at the trade deadline. That helped us just play with freedom.

“I think whatever teams are playing the most free are the teams that win. We’re all talented. I think we’re playing with a lot of freedom right now.”