New York also will receive a player to be named later or cash considerations as part of the deal, which was struck just before the trade deadline.
Montgomery has been a top performer for the Yankees, posting a 3.77 ERA in 272 innings across 51 starts the past two seasons. However, he was 0-2 with a 5.36 ERA in his last eight outings.
"Pretty shocked I guess,'' Montgomery said of being traded.
"I still don't really think I've ever performed the way I should here,'' he added. "A lot better player than I've ever shown, but I think I was consistent and definitely worked my hardest.''
Bader has not played since June 26 because of plantar fasciitis in his right foot. He had played for the Cardinals across six seasons, hitting .256/.303/.370 in 72 games this season with five homers. He won a Gold Glove last year.
"Harrison Bader is one of the elite center-field defenders in the game,'' general manager Brian Cashman said, anticipating Bader will return in September. "So he provides a lot of lanes for us.''
The trade represents a homecoming for the 28-year-old outfielder, who grew up in Bronxville, New York, and was a fan of the Yankees. He is a graduate of Horace Mann School in the Bronx, about 5 miles from Yankee Stadium.
Montgomery joins a rotation with Adam Wainwright and Miles Mikolas and will be an important pitcher for St. Louis moving forward with Steven Matz (knee) currently on the injured list. St. Louis also acquired Jose Quintana from the Pittsburgh Pirates on Monday.
His departure from New York came a day after the team acquired Frankie Montas from Oakland.
"We wanted innings, specifically starting pitching," Cardinals president of baseball operations John Mozeliak said. "We felt like we were getting inconsistency out of our rotation.''
Once he comes off the IL, Bader will join Aaron Judge, Giancarlo Stanton, Matt Carpenter in the Yankees outfield and will likely take some playing time away from Aaron Hicks, who has struggled so far this season, hitting .230/.353/.330 across 91 games.
Both Bader and Montgomery are eligible for free agency after the 2023 season.
St. Louis also got catcher Austin Allen from Oakland on Tuesday for right-hander Carlos Guarate.
Allen was 1 for 14 this season for Oakland and hit .271 with five homers and 26 RBIs for Triple-A Las Vegas. Guarate, 21, is 5-4 with a 4.18 ERA in 12 starts and seven relief appearances for Class A Palm Beach.
Information from The Associated Press was used in this report.