The deal was announced ahead of this weekend's Monaco Grand Prix.
Since leaving McLaren in 2013, Hamilton has competed in 43 races, winning 15 and securing a further 11 podium finishes to replace four-time world champion Sebastian Vettel — the only other driver to beat him this season — as the sport's No. 1 driver.
Hamilton currently leads teammate Nico Rosberg by 20 points after three wins in five races this season.
"Mercedes is my home and I couldn't be happier to be staying here for another three years," Hamilton said. "This is a company filled with real passionate racers, from the board room to the factory floor, and an incredible hunger to win. Even after the success of last year, that hunger is greater than ever - and it's the same for me, too."
Last year, Hamilton won 11 races as he claimed a second world title. His consistency has seen him reach the podium in 21 of the past 24 races since the beginning of last season, with 14 wins, five second-place finishes and two third places. With 36 career race wins, and given Mercedes' superior speed, he should overtake Vettel's 40 wins this year.
"The Mercedes car I am driving right now is the best I have ever had in my career," Hamilton said. "It's just so much fun to be out there every weekend, on the limit and fighting to win at every track. Mercedes-Benz began supporting me in 1998 so I am very proud that this contract means I will mark 20 years with Mercedes in 2018."
Hamilton, who represents himself since splitting with his advisers after last season, fueled the suspense by remaining silent over his future for a long period. He said in March that the new deal was almost signed with only small details left to take care of, but negotiations took a long time to be concluded.
"Continuity is one of the key factors for delivering success in Formula One and we now have that in place," Mercedes head of Motorsport Toto Wolff said. "Lewis enjoyed an historic world championship season with Mercedes-Benz last year and it was a priority for this season to renew his contract for the next term.
"We have taken the right amount of time with the process and not rushed ourselves. The result is a strong agreement that will enhance Lewis' association with the Mercedes-Benz brand, and that recognizes and respects the market value of Lewis and of Mercedes in Formula One."
Mercedes did not reveal the financial aspects of the deal, which is estimated to be worth 90 million pounds ($140 million).Suggest a correction