The Mariners and Rays announced the trade on Tuesday night.
The 24-year-old Ramirez was without a spot in the Mariners' plans after failing to win a job in the rotation during spring training and being out of minor league options.
Montgomery has not pitched in the major leagues. He was drafted by the Royals with the 36th pick in 2008.
The Rays obtained Montgomery as part of the seven-player trade that sent James Shields to Kansas City for Wil Myers before the 2013 season. Montgomery won 10 games last year at Triple-A Durham. He made six relief appearances this spring with the Rays, giving up three runs - two earned - in 11 1-3 innings.
Ramirez has made 35 starts over the past three seasons for Seattle. Last season he was 1-6 with a 5.26 ERA in 17 appearances - 14 starts - with the Mariners.