The 25-year-old, who signed a six-year contract at Real when he joined from Monaco for £71m in July 2014, made just 22 appearances in La Liga last season.
He had been linked with a summer move to both Premier League champions Chelsea as well as Manchester United.
“Signing James Rodríguez was our coach Carlo Ancelotti’s biggest wish,” said Bayern chairman Karl-Heinz Rummenigge.
“We’re delighted we’ve been able to complete this transfer.”
Colombia captain Rodriguez, the top scorer at the 2014 World Cup, was signed by Ancelotti during the Italian’s two-year spell as Real manager.
But the playmaker found his playing time limited under Zinedine Zidane, who succeeded Rafa Benitez as boss of the Spanish giants in January 2016.
He made 111 competitive appearances for Real, scoring 36 goals and providing 41 assists, but was left out of the 18-man squad that beat Juventus in the Champions League final last season.
“James is a very versatile player. He’s a goalscorer himself, he sets up a lot of goals and on top of that he’s great from set-pieces,” continued Rummenigge.
“There’s no question that this transfer further increases the quality in our team.”
Rodriguez has been included in the squad that will travel to China and Singapore on Sunday for a 12-day tour by Bayern, who have won the last five Bundesliga titles.