In exchange, the Pirates received minor league catcher Carter Bins and right-hander Joaquin Tejada.
Pittsburgh thought it had a deal for Anderson with the Philadelphia Phillies earlier Tuesday, but it fell through on medical review, sources told ESPN's Jeff Passan.
Seattle instead moved to acquire the 31-year-old Anderson, who is 5-8 with a 4.35 ERA this season. He's set to become a free agent after the season.
Anderson spent his first four big league seasons with the Colorado Rockies before joining the San Francisco Giants as a free agent last season and then the Pirates this year. He has gone at least five innings in each of his 18 starts in 2021.
Earlier Tuesday, Seattle traded right-hander Kendall Graveman to the Houston Astros as part of a four-player deal that baffled some, considering the Mariners are just one game behind the Oakland Athletics in the AL wild-card race.
But Mariners general manager Jerry Dipoto hinted more moves could be on the way -- which turned out true with the team completing the Anderson deal.
"It probably doesn't [make sense] as a standalone, but it's part of a context that's going to be an ongoing story over the next couple of days'' as the trade deadline nears, Dipoto said when asked why the team traded Graveman.
"What comes next could be as early as tonight or tomorrow because we do plan on being active."
Anderson immediately became the veteran on a totally rebuilt starting rotation. He was scheduled to start Tuesday night against Milwaukee, but was pulled shortly beforehand with his future status up in the air.
Anderson is the second Pirates player to be flipped as Friday's trade deadline nears. All-Star second baseman Adam Frazier was sent to San Diego in return for prospects over the weekend.
The 22-year-old Bins hit a combined .247 with eight homers and 34 RBIs in 50 games at the Double-A and High-A levels this season.
The 18-year-old Tejada pitched five innings this season with the Dominican Summer League Mariners in his professional debut.
Seattle also designated for assignment infielder Jake Hager. The 28-year-old Hager was claimed off waivers from Milwaukee on June 22 and had been in Triple-A for the Mariners.
The Associated Press contributed to this report.