The 28-year-old had played for the German champions since 2012 and scored 33 league goals for the club. According to his new club's sporting director Jose Luis Caminero, he is the perfect fit for the Spanish league winners.
"The signing of Mandzukic is great news because he has the attributes we were looking for in a striker," he said. "He's a strong forward, with a great high ball control and a powerful shot.
"It allows us to start pressing the opposition from the front, because he works hard on playing the ball out of defence. He fits well with his attacking teammates and is used to competing at the highest level. He's a winner, a player used to lifting titles. He'll contribute very much."
Mandzukic has 15 goals in 51 caps for Croatia.