A short statement from Barca said a fee of €25 million (£21.6m) had been agreed for the 22-year-old.
"This agreement also includes holding a friendly match between the two teams, which will be played in the next four years."
Chairman Karl-Heinz Rummenigge added: "Thiago Alcantara was the biggest wish of our new coach Pep Guardiola. We are pleased that we have succeeded in this great transfer.
"Thiago has only just been named the best player at the European Under-21 Championship. He is a fantastic player with great perspective, which will strengthen Bayern."