Glasgow Warriors head coach Townsend, 43, previously worked with Scotland as part of Andy Robinson's backroom staff.
The former Scotland fly-half, who won 82 caps - plus two for the Lions - led Warriors to the Pro12 title in 2015.
"I am incredibly proud. It is a real honour to be given the responsibility of coaching the national team," said Townsend.
"My focus is firmly on the season ahead with Glasgow and I will be doing all I can to help the club continue to progress this year."
New Zealander Cotter, 54, has been in charge of the Scots since 2014 and led them to the World Cup quarter-finals last year.
Shortly before that tournament, the former Clermont Auvergne head coach had extended his contract until 2017.
Scotland lost all five Tests in his first Six Nations but they improved this year with wins over Italy and France, scoring a best-ever 11 tries in a single campaign.
"I believe we have moved forward by working to execute the simple things well," said Cotter, who has now coached in Europe for a decade after an eight-year spell in France with Clermont Auvergne.
"The focus has been to respect tradition but also perform in the present, be adaptive and innovative. I have been really pleased with the progress that has been made."
Media playback is not supported on this device
Scottish Rugby chief executive Mark Dodson thanked Cotter for his "considerable impact" but said the time was right to promote "one of the most sought after coaches in the game", two years out from the next World Cup in 2019.
"The time is right to take the development of the national team forward with Gregor," said Dodson.
"Gregor's playing record showed he is a man of vision and great professionalism, which he has since successfully transferred into his coaching roles.
"It is these factors which I feel will enable Scotland to continue its forward momentum, building on the strong foundations laid by Vern, with the current group of players and future Scotland internationals."
Dodson has now launched a recruitment process to find Townsend's replacement at Glasgow for next season.
Gregor Townsend is to replace Vern Cotter as Scotland head coach in June 2017, Scottish Rugby has announced.