Barca is my home, and I want to spend my life here, says 30-year-old Argentine superstar of Spanish club.
Messi, 30, joined the club in 2000 at the age of 13, and went on to score titles, records, and individual and team awards.
When his new deal concludes, Messi will have played at least 17 seasons for Barcelona.
Individually, he has won the Ballon d’Or award five times, more than any other player in history.
He was also the top scorer in Spain's First Division La Liga four times, and collected four Golden Shoe awards as Europe's top domestic scorer.
"Barca is my home. I [want] to spend my life here, at my home... I always wanted to end my career here. My dream was to end my career with Barcelona and we are on track,” the top striker wrote on Twitter.
To announce the deal, Barcelona's official Twitter account sent out a tweet saying: "He has played 602 games. He has scored 523 goals. He has won 30 trophies. The story continues."
In the new deal, Messi's buyout clause was set as €700 million ($835 million).