In a statement published Thursday, McLaren said it had "extended its relationship" with the Spaniard, who will continue to partner Belgian driver Stoffel Vandoorne.
Alonso looked on the brink of leaving the team earlier this season after a string of retirements and finishes outside the points -- a continuation of the poor form he experienced in 2015 and 2016.
But a switch from Honda to Renault engines announced last month
has seemingly persuaded Alonso that the team can become a competitive force once again.
"It's fantastic to be able to continue my relationship with everybody at McLaren," Alonso said in a statement
on McLaren's official website.
"It was always where my heart was telling me to stay, and I really feel at home here. This is a fantastic team, full of incredible people, with a warmth and friendliness that I've never experienced elsewhere in Formula 1. I'm incredibly happy to be racing here."
"Just as important, McLaren has the technical resource and financial strength to be able to very quickly win races and world championships in F1. Although the last few years have not been easy, we have never forgotten how to win, and I believe we can achieve that again soon.
"The last three years have given us the momentum to plan and build for the future, and I'm looking forward to that journey. I'm excited for our future together -- and I'm already working hard to make it a success."
One of the most revered names in modern motorsport, Alonso won his two world titles with Renault in 2005 and 2006 and finished runner up three times during a five-year stint with Ferrari from 2010 to 2014.
The return to McLaren in 2015 -- he spent a season partnering Lewis Hamilton in 2007 -- was meant to herald a new beginning for both Alonso and McLaren, who won four consecutive constructors' world titles powered by the Japanese manufacturer from 1988 to 1991.
But the reunion quickly turned sour as Honda's hybrid turbo engine lagged far behind expectations with Alonso managing 11 points in 2015. The following year he scored 54 and in 2017 he has just 10 points from 15 starts.
Andretti: Alonso 'deserves' success
Mario Andretti, who won the 1978 F1 world title, has long been a fan of Alonso, but his admiration has grown after watching how the Spaniard took on the task of racing at the Indianapolis 500 in May.
Andretti is hopeful that Alonso and McLaren can rekindle their respective glory years.
"McLaren, that is one brand that has never not been competitive for any period of time so it's time for them to resurge," Andretti told CNN.
"You can see they have the chassis. You could see at Hungary -- they are right there. I hope that Renault is the answer -- that's yet to be seen. In their own mind I'm sure McLaren made the right decision so I hope that they did," he added.
"McLaren deserve it -- they really do. And so does Fernando.
"Fernando is a pure racer and there's no better assessment than that for us, in our world, to call someone a racer.
"There are racing drivers and then then there are racers. He's a pure racer."