The Rays received minor league right-hander Tobias Myers in exchange for Beckham, who is hitting .259 with 12 home runs and 36 RBIs in 87 games this season.
Beckham was the top overall selection by Tampa Bay in the 2008 amateur draft but saw his playing time dwindle after the Rays acquired shortstop Adeiny Hechavarria from the Miami Marlins.
With injured Orioles shortstop J.J. Hardy set to become a free agent after the season, Beckham, 27, could factor into Baltimore's plans at the position for the future.
Myers, 18, was a first-round draft pick out of high school in 2016. He made seven starts at Aberdeen of the New York-Penn League, going 2-2 with a 3.94 ERA.