Hartley, 27, will be the ninth Kiwi to get behind the wheel of an F1 auto and the first since Mike Thackwell in 1984 when he replaces Frenchman Pierre Gasly at the Circuit of the Americas (COTA) track in Austin, the Red Bull-owned team said.
"What an awesome feeling, I never did give up on my ambition and childhood dream to reach F1", said Hartley, who won the 24 Hours of Le Mans in June.
When Hartley was dropped from the Red Bull junior driver programme in mid-2010, he left F1 and turned instead to sportscar racing.
Gasly has clashing commitments in Japan, where he will be trying to win the Super Formula championship for the Mugen Honda team, but is set to return for the final three rounds of the season. COTA is a track I really enjoy and one I have raced at recently.
"I want to say a huge thanks to Red Bull for making this a reality, and to Porsche for allowing me to do this alongside the World Endurance Championship". With Carlos Sainz departing to Renault, the team looks set to hand a full-time role to Gasly, who impressed in Malaysia and Japan, but the team has doubts about Kvyat, who has endured a hard time since being demoted from Red Bull in 2016.
"What an fantastic feeling!" said Hartley, whose F1 hopes looked to have ended when he left Red Bull in 2010.
Hartley followed up that triumph with victory at Le Mans this year and another WEC title.
Toro Rosso boss Franz Tost said he was delighted for Hartley, describing him as part of the Red Bull family.
Hartley will partner Kvyat in the United States of America, with the latter having regained a Toro Rosso seat due to Carlos Sainz's move to Renault being brought forward.
Hartley is no stranger to Toro Rosso, having tested for the team back in 2009.
He becomes the first New Zealander since Mike Thackwell in 1984 to compete in motorsport's premier category and just the ninth overall.