Rodriguez, 25, had been linked with both Chelsea and Manchester United following a difficult 2016-17 campaign in Madrid.
However, Bayern have swooped in to announce the shock arrival of the Colombian international, who will spend the next two years on loan with the German champions before potentially joining on a permanent deal.
"FC Bayern Munich and Real Madrid have agreed on the change of Colombian national player James Rodriguez to the German championship on Tuesday," read a statement from Bayern.
"The two clubs agreed on a two-year loan transaction until June 30, 2019 with the following purchase option for FC Bayern Munich. James Rodriguez will sign his contract in Munich after successfully completing the compulsory medical check."
Meanwhile, Bayern CEO Karl-Heinz Rummenigge added: "We are delighted to have realised this transfer. It was our coach Carlo Ancelotti's big wish to sign James Rodriguez with whom he worked successfully at Madrid already.
"James is a versatile player. He's dangerous in front of the goal, sets up a lot of strikes and kicks great set pieces. Without a doubt, we've increased the quality of our squad with this transfer once again."
Rodriguez has scored 36 goals in 110 appearances for Real Madrid following a 2014 move from AS Monaco. Last season, the Colombian scored 11 times in all competitions, but he started just 13 of Real Madrid's 38 La Liga fixtures.