Frenchman Gasly is expected to return for the final grands prix in Mexico, Brazil and Abu Dhabi, and also to retain the seat into next year.
He became world endurance champion in 2015 for Porsche driving alongside former F1 driver Mark Webber and German Timo Bernhard.
The shake-up was required because Spaniard Carlos Sainz has moved to Renault for the final four races of this season in preparation for a full year with the French team on loan from Red Bull in 2018.
#8220;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.
New Zealander Brendon Hartley is to make his Formula 1 debut for Toro Rosso at next weekend#8217;s US Grand Prix.
Hartley is leading the world endurance series again this year and could become champion at this weekend#8217;s race at the Fuji Speedway in Japan.
The other car will be driven by Daniil Kvyat, who returns after being dropped in favour of Gasly two races ago.