The 30-year-old, who was linked with the Arsenal job before Unai Emery's appointment, has activated an exit clause in his contract, which was due to expire at the end of the 2020-21 campaign.
Nagelsmann has steered Hoffenheim to back-to-back top-four finishes in the Bundesliga, and will lead the German club in the group stages of the Champions League next season.
"I owe it to TSG and all of its employees, as well as to the tram and the fans, that this historic season in which we are competing in the Champions League for the first time, to not have any constant assumptions about my future," Nagelsmann told the club's official website.
"Now everyone knows what they are about and we can focus professionally on the upcoming tasks. Everyone knows I will be doing everything I can to reach our ambitious goals until the last hour of my commitment to TSG."
OFFICIAL: Julian #Nagelsmann will become RB Leipzig head coach from the 2019/20 season.— RB Leipzig English (@RBLeipzig_EN) June 21, 2018
The 30-year-old joins from @achtzehn99_en and has agreed a contract with #DieRotenBullen until 2023. #Nagelsmann2019 pic.twitter.com/DVRrvBHR4c
Nagelsmann represented 1860 Munich and Augsburg as a youth during his playing days, but was forced to retire at Under-19 level due to persistent knee problems.