Carlos Sainz will join McLaren next year as replacement for Fernando Alonso, the Woking-based team announced on Thursday.
As reported by Motorsport.com, Sainz emerged as a favoured choice by McLaren as it assessed its options for 2019, when it will lose two-time world champion Fernando Alonso.
McLaren has now confirmed Sainz as one of its 2019 drivers on a multi-year deal.
"We're incredibly excited to have Carlos join us as a McLaren driver," said McLaren CEO Zak Brown.
"We've been assessing him for some time now and rate him very highly among the next generation of young talent emerging through the ranks in Formula 1."
The main complication McLaren faced with Sainz was his contractual situation with Red Bull.
Sainz is on loan from Red Bull at Renault this season but his long-time backer retained an option to recall him to the senior team until September.
With Ricciardo making the shock decision to quit Red Bull for Renault, taking Sainz's seat, McLaren had to wait until Red Bull decided whether to promote Sainz or Gasly.
Thursday's confirmation that Sainz will race for the Woking team next season means Red Bull has relinquished its option early and indicates it has committed to Toro Rosso driver Gasly partnering Max Verstappen next season.
Sainz said: "I'm delighted to finally be able to confirm that I'll be a McLaren driver from the 2019 season.
"It's something I've been looking at for a while and I'm very excited about this next chapter in my career."
Sainz is a proven operator in F1's midfield and gives McLaren a good insurance policy as it debates what to do with the drivers already on its books.
Reserve driver Lando Norris, Mercedes junior Esteban Ocon and current McLaren racer Stoffel Vandoorne are all linked to the second seat.
The team says it will announce its second driver "in due course".
McLaren is unconvinced by Vandoorne, who has been comfortably eclipsed as Alonso's teammate, but has also appeared uncertain about when to promote reserve driver Lando Norris.
As Alonso's exit meant both McLaren drives became available instead of one, Formula 2 title challenger Norris now has a much more concrete chance to race in F1 next year.
However, he is believed to face competition from current Force India driver Ocon, whom Mercedes is looking to place somewhere on loan.
Mercedes had attempted to send Ocon to Renault, but Ricciardo's move scotched that.
It has therefore revived negotiations with McLaren, having previously considered it a viable destination for Ocon before it pushed him towards Renault.
Vandoorne's chances of staying in F1 appear limited if he is dropped by McLaren.
He could try to take advantage of the Gasly and Sainz moves to force himself into Toro Rosso but that would require Red Bull taking the unusual step of picking up a driver rejected by one of its rivals.
Alternatively, he may turn to old ART GP2 title-winning boss Fred Vasseur, who runs the Sauber team, which features Vandoorne's manager Alessandro Alunni Bravi in its ownership structure.