The Brewers announced they had shipped McGehee to the Pirates in return for right-handed reliever Jose Veras.
McGehee struggled this season to regain his form of 2009 and 2010, batting .223 with a .270 on-base average in 155 games for Milwaukee.
His trade leaves an infield spot open for free agent former Chicago Cubs slugger Ramirez.
Multiple reports indicated Monday the Brewers and Ramirez had reached an agreement on a contract.
Veras posted a 3.80 ERA in a career-high 79 games for Pittsburgh in 2011. He has also played for the Yankees, Indians and Marlins.