Hamilton’s deal with Mercedes was due to expire at the end of the season and the two parties have been in protracted negotiations over a new contract.
The team had hoped to have an agreement in place by the beginning of the season in March but the uncertainty over Hamilton’s future has been dragged out.
Hamilton said: “I have been in the Mercedes Family since 1998.
“I am forever grateful for their continued support, love and protection over these years.
“I’m incredibly proud of what we have achieved together and even more excited for the future!”
Earlier on Thursday morning, Mercedes released a picture of a blank contract with the caption “#Announce…” while Hamilton himself trailed the announcement on his Instagram story with the message “Got some exciting news coming today”.
And 20 minutes later Mercedes confirmed a two-year extension for Hamilton on his current deal.
“This contract extension has basically been a formality since Toto and I sat down during the winter, so it’s good to put pen to paper, announce it and then get on with business as usual,” Hamilton said.
“I have been part of the Mercedes racing family for 20 years and I have never been happier inside a team than I am right now.
“We are on the same wavelength both on and off track – and I am looking forward to winning more in the future and shining even more light on the three-pointed star.
“I’m very confident that Mercedes is the right place to be over the coming years.
“Although we have enjoyed so much success together since 2013, Mercedes is hungrier than ever – from Dr Zetsche and the board members at the top of Daimler, through Toto and the team management, to every single person I meet in the corridors of Brixworth and Brackley.
“The competitive passion that burns bright inside me is shared by every single member of this group – always chasing the next improvement and digging even deeper to make sure we come out on top.
“I can’t wait to see what we can achieve together in the next two-and-a-half seasons.”
There had been rumours that Mercedes would try to announce the signing at the iconic British Grand Prix, Hamilton’s home race, but nothing materialised at the July 8 event.
The deal is expected to trigger a number of other confirmations with Daniel Ricciardo understood to be holding out on Red Bull until Hamilton makes his future plans clear.
And former McLaren driver David Coulthard told Express Sport two weeks ago that most decisions had already been made.
“I think that the chairs are all set and the drivers are settled on them,” Coulthard told Express Sport ahead of the British Grand Prix.
“Lewis is going to get a deal done with Mercedes, then the obvious thing is for Daniel to stay at Red Bull. Then Carlos Sainz can get locked in to Renault.
“The only real rumour is that [Charles] Leclerc has signed a two-year deal with Ferrari which would mean Kimi [Raikkonen] stopping.”