The New Zealander will be joined next year by current Toro Rosso team-mate Pierre Gasly, in what will be the first full season of Formula 1 for both drivers.

For Hartley, the news is a dream come true, a spectacular return to the sport’s upper echelons after his career had appeared to be all but over.

Hartley had been part of the Red Bull junior driver squad during the late 2000s and had been tipped to progress to a Toro Rosso F1 drive. Instead, he was dropped from the programme, and left to pick up sundry sports car drives where he could.

But just when his hopes of making it professionally seemed dashed, the young Kiwi was picked up by Porsche for its LMP1 sports prototype campaign.

This year in what was Porsche’s final year of its LMP1 programme, Hartley won both the World Endurance Championship and the Le Mans 24 Hour.

Last month when Toro Rosso dropped the underperforming Daniil Kvyat, and Carlos Sainz was released to join Renault, team boss Franz Tost elected to trial former Red Bull junior Hartley along with current Red Bull junior Gasly in the remaining grands prix of 2017.

"It's very satisfying to have converted an opportunity that came as a surprise into a 2018 F1 drive,” Hartley said.

“I couldn't be happier. I'd like to thank Red Bull and Toro Rosso for believing in me and giving me this second chance – dreams can come true.

"I'm now going to carry on working harder than ever in order to finish this busy end of season on a high and start the new year as strong as possible... Bring it!"

Team boss Franz Tost said he was pleased to be able to confirm his two drivers so far out from the start of the 2018 season.

"During this last part of the year they've shown that they're ready for Formula 1, getting to grips with the car quickly, showing good performances and always demonstrating to be prepared for the challenge.

"As we know, F1 is something that not all drivers can adapt to this fast.

"Therefore, we're looking forward to having a full year with them; one where we can hopefully provide them with a good package which, combined with driver consistency, can surely put them in the best possible situation to deliver."