The Briton's arrival is likely to send seven-times world champion Michael Schumacher into retirement.
"It is now time for me to take on a fresh challenge and I am very excited to begin a new chapter," said Hamilton, who will partner Nico Rosberg, his former karting team-mate and friend.
"Mercedes-Benz has such an incredible heritage in motorsport, along with a passion for winning which I share.
"Together, we can grow and rise to this new challenge. I believe that I can help steer the Silver Arrows to the top and achieve our joint ambitions of winning the world championships."
Mercedes team principal Ross Brawn said that the arrival of the 2008 world champion heralds the start of a sustained bid for world championships.
"I believe that the combination of Lewis and Nico will be the most dynamic and exciting pairing on the grid next year and I am looking forward to what we can achieve together," he said.
"Over the past three years, we have been putting in place the foundations and building blocks that are needed to compete regularly for the world championship. The potential is now there to match any other team on the grid."
Mercedes took over champions Brawn GP at the end of 2009 but have had only one victory - Rosberg's success in this year's Chinese Grand Prix - to celebrate.
While that was the first by a works Mercedes since 1955, McLaren are regular challengers for the title and have won five times this year - three of them provided by Hamilton.
On paper, Hamilton is swapping a place with proven winners for a British-based team with little success but plenty of potential. Mercedes also make the engines used by McLaren and have a substantial development budget.
Brawn has a highly impressive track record after multiple championships as technical director at Benetton and Ferrari and boss of the Brawn team he saved after previous owners Honda pulled out in late 2008.
Mexican Perez, 22, has signed a "multi-year deal" with Woking marque McLaren, where Hamilton has been developed since the age of 13.
Hamilton's contract negotiations have been a running saga all season with reports that he was close to a deal with Mercedes emerging early in September.
More recent indications were, however, that the 27-year-old was in favour of staying at the team that handed him his Formula One debut in 2007.
The Daily Mail reported that Hamilton's contract is worth £60m with a basic annual salary of around £15m.
Mercedes had made no secret of their desire to sign Hamilton in place of Schumacher, the sport's most successful driver, whose return to the sport after retiring from Ferrari in 2006 has been unremarkable.
Schumacher has been on the podium just once since he began his comeback in 2010 and has retired from half of the 14 races this season.
Schumacher released a statement thanking Mercedes.
"I have had three nice years with the team which unfortunately did not go as well as we all would have wanted on the sporting side," he said.
"I wish Lewis well and for the team to achieve the success we worked so hard for in the build-up. I would like to thank the team for their trust and all the guys for their unconditional commitment."
Brawn said: "On behalf of Mercedes, I would first of all like to thank Michael Schumacher for the important contribution he has made to the growth of our team over the past three seasons.
"His energy and commitment have never wavered, even when results have not matched our own expectations, and we are determined to finish the 2012 season together on a high. As always, it has been a pleasure to work with Michael."
Peter Sauber said recently that he would offer Schumacher a drive with his eponymous team, should he leave Mercedes.