The Woking-based team are currently supplied by Renault, having joined forces with the French company last year.
They will see out that deal, which runs until the end of 2020, before making the switch back to Mercedes as part of a long-term agreement until at least 2024.
"We are delighted to welcome McLaren back to the Mercedes-Benz racing family with this new power unit supply agreement," said Mercedes' motorsports head Toto Wolff in a joint statement with McLaren issued at the Russian Grand Prix on Saturday.
"We hope that this new long-term agreement marks another milestone for McLaren as they aim to take the fight to the sport's top teams, including our Mercedes works team."
The McLaren-Mercedes partnership initially ran from 1995 to the end of 2014.
It turned McLaren, enduring a slump after their heady days of dominance during the late 1980s and early 90s with Honda, into a force to be reckoned with once again.
The combination won 78 races, a constructors' title and three drivers' titles with Mika Hakkinen (1998, 1999) and Lewis Hamilton who raced to his first Formula One title with the team in 2008.
McLaren find themselves in a similar phase now, rebuilding after three dismal years with Honda, the Japanese manufacturer they rejoined forces with at the end of 2014 in a bid to recreate their dominance from 30 years ago.
Fielding a fresh driver line up of British rookie Lando Norris and Spaniard Carlos Sainz, they have made big strides this year and are currently locked in a battle for fourth in the overall standings with Renault's works team.
But they haven't won a race since the season-ending 2012 Brazilian Grand Prix, when they were still powered by Mercedes.
"Renault has been instrumental to our Formula One recovery plan and a fantastic partner to McLaren Racing," said Zak Brown, chief executive of McLaren Racing.
"This agreement is an important step in our long-term plan to return to success in Formula One."
McLaren's new deal with the German manufacturer, whose power units have set the benchmark in Formula One's turbo-hybrid era, coincides with a planned rules overhaul aimed at leveling the playing field and creating better racing.
The shake-up could be just what a team like McLaren need to make that final jump up to the top.
Mercedes are set to supply four of Formula One's 10 teams following the McLaren deal, including their own factory outfit, former champions Williams and Canadian team Racing Point.