It had been reported earlier this week that the 21-year-old was in line to replace Perez at the British-based team after winning the Formula Renault 3.5 feeder series.
Perez confirmed on Wednesday that he would be departing the team after just one season, which left the door open for Magnussen to take the seat of the former Sauber driver.
Magnussen said: "I am absolutely overjoyed to be making my Formula 1 debut with McLaren. I will put it simply - this team is the best.
"It has been my dream to drive for McLaren ever since I was a small kid, and it's no exaggeration to say that I have dedicated almost every day of my life to achieving the goal of becoming a McLaren Formula 1 driver."
The Dane becomes the first rookie driver to be taken on by McLaren since they signed Lewis Hamilton in 2007.