Superstar Messi has the option of an extra season which could see his association with the Catalan side extend to 21 years.
Barca have also added a £265m release clause in the contract to prevent poachers, such as former boss Pep Guardiola stealing in with Manchester City.
The 30-year-old is currently on his honeymoon following his “wedding of the century” to childhood sweetheart Antonella Roccuzzo. He’ll sign the deal when he returns to pre-season training.
A statement released on the club’s official website, www.fcbarcelona.com, said: “FC Barcelona and Leo Messi have agreed on a contract renewal that will keep the Argentinian at the club until June 30th, 2021.
“The deal will be signed in the coming weeks, when Messi returns to the team for pre-season training.”
Messi has been at Barca since he was 13 – after moving over from native Argentina – and made his senior debut as a 16-year-old in a friendly against Porto.
He has helped the club win eight La Liga titles, five Copa del Reys, and four Champions League trophies during his time there.
He scored the first of his club record 507 goals – from just 583 matches – against Albacete in May 2005 and has since claimed the Ballon d’Or on five occasions, more than any other player.
The statement continued: “The club is very happy with both the renewal and the commitment of Messi, the best player in history, who has played his full professional career at Barca and has led the team to an era of extraordinary success, the likes of which has never been seen in world football.”
However, the club which finished second to Spanish champions Real Madrid and bowed out of the Champions League at the quarter-final stage last season is expecting much, much more from its star man.
The statement added: “Leo Messi has since gone on to break just about every record and has become the greatest player in the world.
“Now, at 30 years of age, Messi has completed 13 seasons with the first team and, with his new deal, will remain for a further four.
“But Leo Messi will not stop there – the Argentinian is in one of the best moments of his career and still has a lot more left to give, which is music to the ears of all Barca fans who will get to continue marvelling at his greatness for at least another four years.”