"We've been planning this for some time," Scottish rugby Chief Executive Mark Dodson told the federation's website. "He's an outstanding coach and he's in demand across the world."
Townsend, 43, already has experience of working with Scotland, having been part of Andy Robinson's backroom staff between 2009 and 2012.
He represented Scotland 82 times in a 10-year international playing career and guided Warriors to the Pro12 last year - when they became the first Scottish side to win the title - having taken over in 2012.
News that makes sense
Your trusted source for staying up-to-date with the world around you. Get free daily news updates and analysis, straight to your inbox.
"He's the first Scottish coach of his generation that has the ability to become the Scotland head coach," Dodson added. "He's been nurtured here through Scottish rugby over the last five years.
"With the success he's had in Glasgow, winning the Pro12 and also making an outstanding, competitive team, we felt this was the right time for him to join us in between the World Cup cycles and to take us to Japan and beyond."
(Reporting by Ed Dove; editing by Ken Ferris and Jan Harvey)
