Perez takes Hamilton's place at McLaren
Hamilton, the 2008 world champion, is expected to join Mercedes in a deal that will likely see Michael Schumacher go back into retirement at the age of 43 after three unproductive years with that team.
"Sergio's new deal means that he will begin a driving partnership with 2009 world champion Jenson Button," McLaren said in a statement, adding it had signed Perez from Sauber on a multi-year deal.
The 22-year-old has been one of the revelations of the season with three podium finishes in 14 races for the Swiss-based team.
Perez, who is currently a member of Ferrari's young driver academy, said he was honoured to be joining McLaren.
"For more than 40 years McLaren has been a team that every racing driver has aspired to drive for -- I was brought up on the great stories of Ayrton Senna's many world championship triumphs for McLaren - and I'm truly honoured that they've chosen me to partner Jenson from 2013 onwards," he said.
Perez thanked Peter Sauber for giving him the chance to race in Formula One and McLaren for handing him the opportunity to take a big step up.
"I'm under no illusion that it is indeed a very big step -- as it would be for any driver -- but I'm ready for it," he said.
"It's fantastic that all the sacrifices I've made are now paying off."
McLaren team principal Martin Whitmarsh said the team had been monitoring Perez for some months.
"We're convinced that he's not only talented and quick, but also that he's willing and eager to learn," he said. "He's perfectly poised to develop into a world championship challenger."
Ferrari President Luca di Montezemolo had said repeatedly that Perez was not ready to race for the Italian team, who have Brazilian Felipe Massa out of contract at the end of the season.
The Mexican's departure will now trigger a race to fill the vacancy at Sauber.