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.
German champions Bayern Munich have signed Morocco defender Mehdi Benatia from Roma for an undisclosed fee.