Appointed in February 2016, the 30-year-old has led Hoffenheim to successive top-four league finishes, and they will start his final campaign in the group stages of the Champions League.
Despite being under contract until June 2021, the highly-rated head coach has triggered an exit clause in his deal.
"It was important to me to ensure clear conditions," Nagelsmann said in a statement on the club's website.
"I owe it to Hoffenheim and all of its employees, as well as to the team and the fans, in a historic season in which we are competing in the Champions League for the first time, not to have constant assumptions about me and my future. Now everyone knows and we can focus professionally on the upcoming, difficult tasks.
"Everyone knows that I will be burning and doing everything I can to reach our ambitious goals until the last hour of my commitment to Hoffenheim."
RB Leipzig then wasted no time in snapping up the coach at the end of next season, with confirmation coming from the side just minutes after Hoffenheim's statement was released.
Hoffenheim will not rush to announce a replacement for Nagelsmann, who took over in charge after Huub Stevens stepped down due to health reasons.
"We knew about the contractual option, which is not exceptional in professional football," director of football Alexander Rosen said.
"It speaks for the character of Julian, that he has now laid the cards publicly on the table and created so early for all clarity."