Paul Goldschmidt was a high school senior, watching from the upper deck in Houston, when Albert Pujols blasted a titanic home run for the St. Louis Cardinals in the 2005 National League Championship Series. The Cardinals had been one out from elimination, but the great Pujols saved them. St. Louis would lose that series, but Pujols went on to lead them to two World Series titles in later years.

“I had a good view,” Goldschmidt said in an interview a few years ago. “It was crazy. I was like every fan there. I was upset.”

Goldschmidt rooted for the Astros then, and before long he would become an All-Star first baseman for the Arizona Diamondbacks. But with one year to go before he hits free agency, the downsizing Diamondbacks traded Goldschmidt on Wednesday to the Cardinals, who finally found a fearsome slugger to replace Pujols in the middle of their lineup.

In exchange for Goldschmidt, the Diamondbacks acquired starter Luke Weaver, catcher Carson Kelly, the Class AA infielder Andrew Young and a competitive-balance round B draft pick in 2019. Weaver was 7-11 with a 4.95 earned run average last season, and while Kelly has hit only .154 in the majors, he was blocked by Yadier Molina in St. Louis and has ranked among baseball’s best prospects.

The Cardinals’ last title came in 2011, Pujols’s final season before leaving for the Los Angeles Angels in free agency. The Cardinals did not suffer immediately, reaching the postseason four times after he departed and winning the National League pennant in 2013. But last season was the Cardinals’ third in a row without a playoff appearance, and they have badly needed an offensive force.

Pujols played 11 seasons for the Cardinals, always hitting at least 30 homers with an on-base plus slugging percentage of .900 or better. Since then, no Cardinal has reached those levels in the same season. Goldschmidt has done it four times, including last season, when he had 33 homers and a .922 O.P.S.

Even so, the Cardinals had a fairly productive offense last season and rallied from a slow start to go 88-74, the best record of any non-playoff team in the National League. The Diamondbacks had an opposite itinerary: after leading the N.L. West at the start of September, they lost 19 of 27 games in that month to finish 82-80.

The Diamondbacks lost J.D. Martinez in free agency to the Boston Red Sox last winter, and this week lost an All-Star starter, Patrick Corbin, to the Washington Nationals as a free agent. Center fielder A.J. Pollock, a former All-Star who is also a free agent, may be the next to leave.

Diamondbacks General Manager Mike Hazen called Wednesday a bittersweet day, suggesting that Goldschmidt was “possibly the best player in the National League” and acknowledging that he was the franchise’s most visible star. He said the Cardinals’ package would help fortify a thin base of talent.

“We’ve worked pretty hard to try to build that talent infrastructure,” said Hazen, who was hired in October 2016. “We don’t feel like it’s where it needs to be. I think we’re still talking about a bottom-10 farm system in baseball. That’s something we’re working aggressively to try to improve to be able to sustain success, not just get there for any one year.”

The Diamondbacks never advanced past the division series with Goldschmidt in the lineup, despite adding the ace starter Zack Greinke for six years and $206.5 million before the 2016 season. That deal gives Greinke the highest average annual salary in the majors ($34.4 million), and while Hazen said he did not envision “a rash of trades,” it stands to reason that he will also move Greinke if he can.

As for the Cardinals, they have tried and failed in recent years to lure superstars for the long term, pursuing David Price and Jason Heyward in free agency and Giancarlo Stanton in a trade. While they could not persuade Heyward to stay after a one-season cameo, they once had a knack for retaining stars who arrived without a long-term contract, like Mark McGwire, Jim Edmonds and Matt Holliday.

Keeping Goldschmidt will be their next challenge. But for next season, at least, the Cardinals should finally have the run producer they have been missing.