Lionel Messi has signed a new deal to stay at Barcelona until 2021, with the Catalan giants inserting a €700 million (US$835 million) buyout clause into the terms.

Barca said in July that Messi had agreed to a contract until June 2021, which would be signed "in the coming weeks".

The lack of confirmation on that agreement had led to talk that Messi could leave Camp Nou, with the Argentina superstar reportedly the subject of an audacious bid from Manchester City for his services.

However, Barca president Josep Maria Bartomeu said earlier this month that Messi had signed three different deals – agreements with his Messi Foundation and one relating to image rights to run alongside the contract of employment – to cement his long-term future at the club.

And the long-running saga finally came to end on Saturday, with Messi putting pen to paper on his fresh terms with the five-time European champions, the mammoth buyout clause dwarfing the €222 million (US$265 million) Paris Saint-Germain spent to pry Neymar away from Barca in August.

Messi will be 34 when his newest extension reaches its expiration, and will have spent 17 years as a professional at Barca, having made his debut in 2004 after progressing from the club's famed La Masia academy.

His time to date has yielded 523 goals from 602 appearances, while Messi has picked up eight LaLiga titles and four Champions League crowns among a lengthy list of honors.

A winner of five Ballons d'Or, Messi also picked up his fourth Golden Shoe award on Friday after finishing as Europe's top league goalscorer in 2016-17.