Sadio Mane spent six seasons with Liverpool, scoring 120 goals in 269 games
The Reds will receive 32m euros (£27.4m) with an additional 6m euros based on appearances, plus 3m euros for individual and team achievements.
Liverpool turned down two bids from Bayern before agreeing a fee for the Senegal forward, who was under contract until next summer.
"This is the right time for this challenge," said the 30-year-old.
"I felt the great interest of this big club from the start so there was no doubt in my mind."
Mane joined Liverpool for £34m from Southampton in June 2016, and scored 120 goals in 269 games, finishing last season with 23 goals in all competitions.
"Sadio Mane is a world star who underscores the appeal of FC Bayern and increases the attractiveness of the entire Bundesliga," said Bayern president Herbert Hainer. "It is for such unique footballers that the fans come to the stadiums."
Mane helped Liverpool win the Champions League and the Premier League, and in February scored the winning penalty as Senegal won the Africa Cup of Nations for the first time.
"With his outstanding performances and his great successes at the highest international level over many years, there are very few players like him in the world," added Bayern's chief executive Oliver Kahn.
"We're sure that Sadio Mane will delight our fans in the coming years with his spectacular style of play. He's ambitious and eager to win more titles. This package is very strong. With players like him at FC Bayern, all the biggest goals are possible."
Last week Liverpool confirmed the signing of Uruguay forward Darwin Nunez from Benfica for an initial £64m.
In a farewell interview for the Liverpool website, Mane said: "It is really strange to no longer be a Liverpool player but I had an unbelievable time. I am going to be Liverpool's number one fan forever."
With Jurgen Klopp having been appointed Liverpool manager in October 2015, Mane was the German's first major signing at Anfield the following summer.
Roberto Firmino was already at the club and Mohammed Salah arrived in 2017 to complete what would become one of the greatest forward lines in Premier League history.
In five seasons in all competitions, they scored 338 goals between them, helping Liverpool become champions of Europe for the sixth time in 2019 and then win the English league title for the first time in 30 years.
With the trio moving into or near to their 30s, Liverpool prepared for the evolution of their attacking ranks by signing Diogo Jota and then Luis Diaz, but Mane's departure could be seen as the end of an era at Anfield.
"It's a big moment, there is no point in anyone trying to pretend otherwise," Klopp told the Liverpool website.
"One of Liverpool's greatest ever players is leaving and we must acknowledge how significant this is. But we must not dwell on what we now lose, instead celebrate what we were privileged to have."
Will the summer signings of Nunez and teenager Fabio Carvalho from Fulham, allied with the arrivals of Jota and Diaz, spark a second phase of success for Klopp on Merseyside?
-- Courtesy of BBC Sport