With Sainz set to be announced as Sebastian Vettel's replacement at Ferrari imminently, McLaren confirmed on Thursday that Ricciardo would be joining at the end of the year.
The deal will see seven-time grand prix winner leave Renault, where he has raced for the last two seasons following his departure from Red Bull.
McLaren has been keen on working for Ricciardo for some time, making an approach for the Australian when he weighed up his F1 future in 2018.
Ricciardo ultimately decided to sign for Renault, who finished behind McLaren in the constructors' championship last year.
Lando Norris has also been confirmed as staying at McLaren to partner Ricciardo.
"Signing Daniel is another step forward in our long-term plan and will bring an exciting new dimension to the team, alongside Lando. This is good news for our team, partners and of course our fans," said McLaren Racing CEO Zak Brown.
"I also want to pay tribute to Carlos for the excellent job he has been doing for McLaren in helping our performance recovery plan. He is a real team player and we wish him well for his future beyond McLaren.”
"Daniel is a proven race winner and his experience, commitment and energy will be a valuable addition to McLaren and our mission to return to the front of the field," said McLaren team principal Andreas Seidl.
"With Daniel and Lando as teammates, I believe we have two racers who will continue to excite our fans and help the team grow.
"Carlos is a true professional, a pleasure to work with and we will continue to enjoy going racing with him this year. We all wish him good luck for the next stage in his career when he leaves McLaren."
McLaren had already opened talks with Sainz over a new contract after his impressive display for the team last year, only for Ferrari to swoop for the Spaniard once Vettel's exit was confirmed.
Since returning to F1 as a works team in 2016, Renault has been open in its target to return to the front of the field upon the new set of technical regulations, which now come into force for 2022.
Ricciardo signed for Renault fully aware of the long-term nature of the project, but the team failed to bridge the gap to the leading three teams as hoped through 2019.
Renault is yet to indicate who will replace Ricciardo at the team, but it now holds one of the highest-profile open seats in F1 for next year.
Outgoing Ferrari driver Vettel has been linked with the seat, as has two-time world champion Fernando Alonso, who previously raced for Renault in 2003-06 and 2008-09.
Renault has also been bold in its ambition to have a graduate from its junior academy on the F1 grid by 2021, a possibility strengthened by Ricciardo's departure.
Guanyu Zhou and Christian Lundgaard are the two leading members of the Renault Sport Academy, both racing in Formula 2 this year.