The 27-year-old, who helped Roma finish second in Serie A last season, had been linked with a move to Premier League sides Chelsea and Manchester United.
Bayern were looking for a defender after Spain international Javi Martinez was ruled out until the New Year with ruptured cruciate knee ligaments.
Roma have replaced Benatia with Olympiakos defender Kostas Manolas.

Sports minister Dayasiri Jayasekara told Sri Lanka's players they were too fat after they failed to reach the Champions Trophy semi-finals.
Malinga, 33, responded by saying he did not care for criticism "from those who are simply warming chairs".
"What does a monkey know about a parrot's nesting hollow?" he added.
"This is like a monkey getting into a parrot's nest and talking about it."
Jayasekara said Malinga's comments were a breach of his contract with the country's cricket board.
"In my criticism of the appalling fitness levels of our players, I did not name Malinga, but he has chosen to put the hat on and attack me publicly," he added.
Malinga won the Indian Premier League title with the Mumbai Indians before the Champions Trophy, and missed Sri Lanka's high-altitude training.
Jayasekara spoke out after Pakistan skipper Sarfraz Ahmed was dropped twice off the bowling of Malinga as Sri Lanka failed to progress from their Champions Trophy group.
"The typical body fat amounts for a cricketer should be about 16%, but most of our players have over 25%," he said.
"I want the results analysed and in future no-one will be included in a national squad if they are above 16%."

The 27-year-old has played in two Tests, 48 one-day internationals and 18 Twenty20 matches for Pakistan.
Both men were later bailed until April pending further inquiries.
Jamshed is among three players who were recently suspended for violating a cricket anti-corruption code.
The Pakistan Cricket Board (PCB) also suspended Pakistan internationals Sharjeel Khan and Khalid Latif, who are due to appear in front of the board on Wednesday.
Jamshed has not commented on the allegations.
The spot-fixing allegations relate to the Pakistan Super League - the country's top-flight cricket championship which is held in the United Arab Emirates for security reasons.
Khan and Latif play in the Pakistan Super League for current champions Islamabad United.
The PCB previously said it was investigating "an international syndicate which is believed to be attempting to corrupt the PSL".
German champions Bayern Munich have signed Morocco defender Mehdi Benatia from Roma for an undisclosed fee.
[NEXT_CONCEPT]
Fast bowler Lasith Malinga is being investigated by Sri Lanka's cricket board after comparing the country's sports minister to a monkey.
[NEXT_CONCEPT]
Pakistan batsman Nasir Jamshed was one of two men arrested by the National Crime Agency in Britain on Monday as part of an investigation into cricket corruption, the BBC understands.