Hartley, 27, is a former Red Bull junior driver who tested for Toro Rosso twice back in 2009. He will join Daniil Kvyat in a revised line-up as Gasly returns to Japan to contest the Super Formula season finale.
"What an amazing feeling!” said Hartley, who won the Le Mans 24 Hours this season and was world sportscar champion in 2015.
“This opportunity came as somewhat of a surprise, but I never did give up on my ambition and childhood dream to reach F1. I have grown and learnt so much since the days when I was the Red Bull and Toro Rosso reserve driver, and the tough years I went through made me stronger and even more determined.
“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. COTA is a track I really enjoy and one I have raced at recently. I'm trying not to put too many expectations on my F1 debut, but I feel ready for it."
Toro Rosso team principal Franz Tost added that he was ‘convinced’ that Hartley, whose last F1 outing came in a test for Mercedes in 2012, was the right man for the job.
"[Brendon] has been part of the Red Bull family for a long time in different classes, as well as the test and reserve driver for Red Bull Racing and Toro Rosso, will now be back racing for us in Austin.
“We are really happy to have him back in our team. With all the racing experience accumulated over the years, we are convinced that he will do a fantastic job for us."
Having fielded Gasly alongside the departing Carlos Sainz in Japan, Toro Rosso will become the first team since Lotus in 1994 to run an entirely new driver line-up in consecutive Grands Prix.
Hartley, meanwhile, will become the ninth New Zealander to race in F1, but the first since Mike Thackwell in 1984.