The contract, which mirrors a similar extension for the Dutchman's assistant Andries Jonker, was signed in the Swiss city of Basel, where Bayern play in the Champions League on Tuesday.
Despite Bayern's patchy start to the season, club officials have been at pains to say they were committed to van Gaal's staying on.
"We don't change our mind after one defeat," Monday's Bild newspaper quoted chairman Karl-Heinz Rummenigge as saying in reference to Bayern's 2-1 defeat to Mainz on Saturday.
A contract extension would "show clearly the importance of Louis to Bayern."
"We have total confidence in Louis van Gaal. The coach does a great job. It's the team, not the coach, that must react."
Van Gaal, 59, pulled off the double of Bundesliga and German Cup success in his first season at the helm in the last campaign and also guided the team to the Champions League final where they were beaten 2-0 by Inter Milan.
This season, Bayern are ninth in the table with eight points, 10 behind leaders Mainz.