The Woking-based team's current contract ran until the end of 2025 and it had been evaluating its options for the longer term.
But ahead of the F1 season finale in Abu Dhabi, McLaren announced that a new five-year deal was in place.
McLaren has been a partner of Mercedes since 2021, having previously enjoyed a period of world championship success with the company in the late 1990s. It remains the most recent customer winner in F1, with Daniel Ricciardo's triumph at the 2021 Italian GP.
Speaking about the decision to commit to Mercedes, McLaren CEO Zak Brown said that the length of the deal was evidence of how much trust his team had in Mercedes' products.
"Mercedes-Benz have been a brilliant and reliable partner of the McLaren Formula 1 team," he said. "The extension signifies the confidence that our shareholders and the wider team have in their powertrains and the direction we're taking with them into the new era of regulations ahead.
"We have been successful together, both in the last three seasons and when they previously powered the team, so we look forward to the success to come as we continue our journey to fight consistently at the front of the grid."
Mercedes F1 team boss Toto Wolff said that having customer teams on board was essential as grand prix racing moves to the new rules era.
"It has been a cornerstone of our motorsport strategy to work with strong customer teams," explained Wolff. "This has many advantages: it gives a clear competitive benchmark, accelerates our technical learning, and strengthens the overall F1 business case for Mercedes-Benz.
"McLaren have been fierce and fair competitors since 2021, especially in the second half of this season. McLaren's strong performances underline the importance of transparent and equal supply to all customer teams in the sport, if we wish to achieve the goal of ten teams capable of fighting for podium finishes."
Mercedes is already advanced with its efforts on the 2026 power unit, having first started work on it in 2022. The new rules see F1 move to fully sustainable fuel as well as shift towards a greater reliance on electrical power.