The defensive midfielder has signed a five-year contract with the Bundesliga champions after the Spanish side accepted an offer reported to be worth an initial €15 million (£14m/$18m) with another €5m available in bonuses.
Roca joined Espanyol at the age of 11 and progressed through the youth system to make his first-team debut in August 2016.
The 23-year-old made 121 appearances in all competitions for the Catalan side but will continue his career in Germany as part of Hansi Flick's team.
The Spain Under-21 international said he has long dreamed of representing the European champions and is eager to get started with his new club.
“I’m very happy. This is a dream come true for me," Roca told the club's official website when his transfer was confirmed.
"I think Bayern is the best club in the world and has strong tradition. I’m really looking forward to wearing the colours of this great club.”
Bayern's director of football, Hasan Salihamidzic, says he expects a lot from the club's latest signing.
“We’re very happy to have signed Marc Roca," Salihamidzic said.
"He’s an outstanding fit for our team both as a player and a person, and will continue to develop here with us. We’re sure he’ll add great value to our team.”
Roca is Bayern's fourth signing of the current transfer window, following the purchase of Leroy Sane from Manchester City and the free signings of Tanguy Nianzou and Alexander Nubel from Paris Saint-Germain and Schalke, respectively.
He might not be the last piece of business the Bavarian outfit make before the transfer deadline on Monday.
They have already had a bid worth £70m ($89m) for Chelsea winger Callum Hudson-Odoi turned down by the Premier League side.
Meanwhile, Eric Choupo-Moting is close to joining the club on a free transfer, having left PSG at the end of last season. The 31-year-old Cameroon striker is expected to sign a deal that will run until 2022.
Bayern started their Bundesliga campaign with an 8-0 victory against Schalke, but followed up with a 4-1 defeat to Hoffenheim last week.