The AL East-leading Orioles also received minor league infielder Michael Almanzar from Boston in exchange for minor league infielders Jemile Weeks and Ivan De Jesus.
The addition of Johnson provides some infield depth for Baltimore in the wake of Manny Machado's season-ending knee injury and Steve Pearce's abdominal strain. The 32-year-old Johnson hit .212 with six homers and 23 RBIs in 87 games combined for the Yankees and Red Sox. He has played first, second and third base, along with left and right field, this season.
Almanzar, 23, was a Rule 5 pick by the Orioles prior to the season.
Weeks, 27, batted .278 in 62 games for Triple-A Norfolk. De Jesus, 27, hit .282 in 113 games for the Tide.