As part of the deal, Buffalo will receive forwards Patrik Berglund, Vladimir Sobotka and Tage Thompson as well as a 2019 first-round draft pick and 2021 second-round pick.
The deal was made before Buffalo owed O'Reilly a $7.5 million signing bonus.
Per TSN's Bob McKenzie, there was no salary retained in the trade, and the Blues will pay O'Reilly's bonus.
The 27-year-old O'Reilly spent the past three seasons with the Sabres after a six-year stint as a member of the Colorado Avalanche.
Last season was one of O'Reilly's best, as he finished with 24 goals and 37 assists for 61 points in 81 games.
The 2013-14 Lady Byng Memorial Trophy winner as the NHL's most gentlemanly player also had just two penalty minutes last season.
Despite his quality production, O'Reilly's patience seemed to be wearing thin with regard to Buffalo's extended rebuild.
In April, O'Reilly talked about how much losing took a toll on him, per John Vogl of the Buffalo News:
"We're stuck in this mindset of just being OK with losing. I feel it, too. I think it's really crept into myself. Over the course of the year, I've lost myself a lot, where it's just kind of get through, just being OK with just not making a mistake. That's not winning hockey at all, and it's crept into all of our games.
"It's disappointing. It's sad. I feel throughout the year I've lost the love of the game multiple times. You need to get back to it because it's just eating myself up and eats the other guys, too. It's just eating us up, and it's tough."
The Sabres haven't made the playoffs since 2010-11, and they had the NHL's worst record last season.
Although the Blues narrowly missed the playoffs last season, they reached the postseason in each of the previous six campaigns.
In O'Reilly, the Blues are getting one of the NHL's best two-way centers and a player who is under contract for five more seasons at a cap hit of $7.5 million.
O'Reilly will join a strong group of forward holdovers that includes Vladimir Tarasenko, Alex Steen, Jaden Schwartz, Brayden Schenn and Robby Fabbri. St. Louis also signed free-agent forwards David Perron and Tyler Bozak, giving it one of the best forward corps in the league.
Despite losing a quality player, the Sabres got a good haul in return.
The 30-year-old Berglund scored 17 goals in 57 games last season, and he is a three-time 20-goal scorer.
Sobotka, 30, had 31 points last season, which was the second-highest total of his NHL career.
Aside from the picks, the best part of the deal from Buffalo's perspective may be Thompson, as the 20-year-old was the No. 26 overall pick in the 2016 NHL draft.
The 6'5" center had nine points in 41 games with the Blues last season and 18 points in 30 AHL contests.
Berglund and Sobotka are potential trade chips for the rebuilding Sabres, while Thompson has a chance to be a significant part of a young core that includes forwards Jack Eichel, Casey Mittelstadt and Sam Reinhart as well as the 2018 No. 1 overall draft pick in defenseman Rasmus Dahlin.