The 33-year-old, who captained Germany to their 2014 World Cup victory, announced his decision after Bayern’s German Cup last-16 win over Wolfsburg.
It was the defender’s 501st game for the Bundesliga leaders.
“I can continue with my leadership style, giving my best every day, in every training, until the end of the season. I can keep doing it this season but not beyond,” he said.
It means he will leave the German champions a year before his contract expires.
“I’ve been considering it for more than the past year,” he added.
“You have to keep testing yourself, you have to keep asking yourself ‘how is it’, day by day, week by week on the training pitch, what’s the feeling you have.”
The Bayern youth product made his senior debut in 2002 and has won seven Bundesliga titles with the club, as well as the Champions League.
He retired from international football after Germany’s triumph in Brazil in 2014.
Lahm announced his decision to retire at the end of the season after he had played his 501st game for Bayern
Source: BBC Sport