Alonso, twice world champion, announced on Tuesday that he will retire from Formula 1 at the end of the year.
Fellow Spaniard Sainz, 23, is currently on loan at Renault from Red Bull and said it was a “childhood dream” to join McLaren.
“I’ve been a McLaren fan for as long as I can remember,” he added.
“It’s a great name in the sport with an incredible heritage, and the list of drivers that have raced for McLaren over the years are among the heroes of Formula 1.
“Fernando is of course one of them, so it’s particularly special that I’ll be taking his seat as part of the next generation of Spanish racing drivers behind the wheel of a McLaren.”