In a statement, Barca said Messi has "led the team to an era of extraordinary success, the likes of which has never been seen in world football".
"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," the statement added.
Messi's previous deal was scheduled to end in the summer of 2018.
The striker has been previously linked with a move to Manchester City but his new contract ties him to the 24-time La Liga winners until he is 34.
Since breaking into the first team under former Barca boss Frank Rijkaard, Messi has won eight La Liga titles, the Champions League four times and the Copa del Rey on five occasions.