Washington also received a third-round draft pick in 2015 as part of the deal.
Halak went 24-9-4 with a 2.23 goals-against average and a .917 save percentage in 40 games with St. Louis this season. Neuvirth went 4-6-2 with a 2.82 GAA and a .914 save percentage this season with Washington.
Halak starred for Montreal in the 2010 playoffs, when the eighth-seeded Canadiens came back from a 3-1 deficit to stun the Presidents' Trophy-winning Capitals in seven games in the first round. Over the last three games, Halak stopped 131 of 134 shots, including 41 of 42 in a 2-1 victory in Game 7.
"He's played well in Montreal. He's played well in St. Louis. And we hope he can come here and play well," Capitals general manager George McPhee said. "He's a good goalie, and he can get hot."
McPhee said Halak -- who can become a free agent after the season -- and Braden Holtby will split time at goalie as Washington tries to avoid missing the playoffs for the first time since 2007.
"Both guys'll start games," McPhee said. "We'll see where it goes."
The Capitals entered Wednesday 10th in the Eastern Conference; the top eight teams make the postseason.
McPhee said none of the available defensemen "moved the needle." So that led him to the 28-year-old Halak. In eight NHL seasons with Montreal and St. Louis, he has appeared in 260 games, going 139-81-26 with a 2.38 GAA and a .917 save percentage.
Halak was in uniform for only one game with Buffalo. On Sunday, he was asked about the possibility of getting traded again.
"I mean, anything can happen from now on," Halak said. "We've got three more days before the trade deadline. We'll see."
Holtby was 19-13-3 with a 2.94 GAA and a .911 save percentage with Washington this season entering play Wednesday night, but the Philadelphia Flyers chased him after taking a 4-0 lead early in the second period en route to a 6-4 win. He was replaced for the remainder of the game by Philipp Grubauer, who was recalled Wednesday from Hershey of the American Hockey League.
"We love Braden Holtby. Love his talent, love his character, love the way he battles," McPhee said. "He's going to be here a while, a long time. There's lots to like about him."
Neuvirth has played in 134 NHL games, all with Washington, going 59-41-13 with a 2.67 GAA.
"He wasn't happy being the No. 2 (goalie), and so we tried to accommodate him," McPhee said. "And we brought in an experienced guy, and I think it's an upgrade on the tandem, which is what we wanted to accomplish."
Sabres general manager Tim Murray said he's a fan of Neuvirth's and thinks a change of scenery will do the goalie some good.
"For whatever reason, he's a backup there, and he's just not as important as he wants to be," Murray said. "And I think when he gets to feel some love again, or whatever you want to call it, and has an opportunity, that he can get his game back."
Murray went on to say that in Washington, Neuvirth's "stats were pretty good right now on a good team, but not a great team."
About Halak, Murray said: "I would have considered keeping him if there were no trade offers that I liked."
As was the case with Neuvirth, Erat wanted to leave the Capitals. And as was the case with Halak, Penner can become a free agent after this season.
"Like Penner, he's going to be playing for a new contract," McPhee said about Halak. "And they usually play pretty well when they're doing that."
ESPN.com's Pierre LeBrun and The Associated Press contributed to this report.