The Briton had cast doubt over his future in the sport after only agreeing only a one-year deal for the 2021 season but the deal will take his time at the team to at least 11 seasons and into the start of a major rules change next year.
Hamilton said: “We’ve accomplished so much together but we still have a lot to achieve, both on and off the track.
“I’m incredibly proud and grateful of how Mercedes has supported me in my drive to improve diversity and equality in our sport. They have held themselves accountable and made important strides in creating a more diverse team and inclusive environment.
“Thank you to all the dedicated and talented individuals at Mercedes whose hard work makes it all possible and the Board for their continued trust in me.
“We’re entering a new era of car which will be challenging and exciting and I can’t wait to see what else we can achieve together.”
Hamilton has won six of his seven world titles with Mercedes since joining from McLaren in 2012.
Mercedes CEO and Team Principal Toto Wolff said: “As we enter a new era of F1 from 2022 onwards, there can be no better driver to have in our team than Lewis.
“His achievements in this sport speak for themselves, and with his experience, speed and race-craft, he is at the peak of his powers.
“We are relishing the battle we have on our hands this year – and that’s why we also wanted to agree this contract early, so we have no distractions from the competition on track.
“I have always said that as long as Lewis still possesses the fire for racing, he can continue as long as he wants.”