Lionel Messi hopes to end his career at Barcelona after ending months of speculation on Saturday by signing a contract extension to 2021, sealing an agreement reached in July, the club announced.
Barca had said in the summer that Messi, 30, had committed his future to the club but the Argentine had not signed the new deal.
With his previous contract set to expire in 2018, Messi could have left Barca for free next summer had he not extended his deal.
"We have needed to do the signature for some time. It is done and I am happy to remain tied to the club," Messi told Barca TV.
"I have always said I wanted to end my career here, it is my dream to finish at Barcelona and we are on the right track."
Barcelona president Josep Maria Bartomeu said the club needed to change the deal agreed in June to increase Messi's buyout clause to 700 million euros ($835 million) and prevent the danger of a repeat of Neymar's departure when Paris Saint-Germain payed the Brazilian's 222 million-euro buyout clause in August.
"We agreed to sign a new deal with a buyout clause adjusted to the current transfer market," said Bartomeu.
"The buyout clause is 700 million. It allows us to keep Leo Messi where he should be."
Without Neymar, Messi's role as a creator and goalscorer has increased in a Barca side that has unusually built its stunning start to the season on a defensive record of 13 clean sheets in 18 games.
"The departure of Ney has meant a change in the way we play," Messi, who has 16 goals in 19 games this campaign, told Spanish sports daily Marca on Saturday, a day after picking up his fourth Golden Shoe as the top goalscorer in Europe last season.
"We lost a huge amount of attacking potential, but that has benefited us in a defensive sense. Now we are more solid in midfield, we have more structure and that has made us stronger defensively."
Barca first announced an agreement with Messi back on July 5, but pressure has been mounting on Bartomeu to get Messi to put pen to paper after a turbulent summer for the Catalans.
Neymar's departure sparked a crisis and Bartomeu was heavily criticised for failing to ward off PSG with a higher buyout clause and for a haphazard search for replacements in the final weeks of the transfer window.
- 30 trophies, 523 goals -
Bartomeu did see off a vote of no confidence launched by disgruntled fans thanks to Barca's fantastic start to the season, in large part because of Messi's form.
Bartomeu now has the image he craved of a smiling Messi tying the remainder of his peak years to the club.
"The new contract once more proves the relationship between Barca and Leo Messi, the best player in the history of football," added Bartomeu.
"He has always said he is happy at Barca and we are beginning a new era with a new project under Ernesto Valverde that at the moment is going phenomenally well.".
Messi's 30 trophies are, along with teammate Andres Iniesta, the most of any player in Barca's history. The total eight La Liga and four Champions League titles.
The diminutive Argentina captain, who joined Barca at the age of 13, has also smashed 523 goals in 602 games to become the Catalans' all-time top goalscorer.
News of Messi's renewal comes as a huge boost to the leaders of La Liga ahead of Sunday's top-of-the-table clash at Valencia (1945 GMT).
Barca lead a revitalised Valencia by four points, with both Real Madrid and Atletico Madrid a further six points adrift, thanks to a club record start of 11 wins and one draw from 12 games.
Despite leaving Messi on the bench, Barca also sealed their place in the last 16 of the Champions League with a 0-0 draw at Juventus on Wednesday.