The Argentina international's improved deal includes a buyout clause worth 250 million euros, the club said on their website www.fcbarcelona.cat.
Barca president Joan Laporta said this week the 22-year-old, a favourite to win this year's FIFA World Player of the Year award, was poised to agree to a new contract that would make him the club's best-paid player.
Barca gave no details of Messi's annual net salary but Spanish media reported he would be earning 10.5 million euros per season after taxes.
"It's a huge piece of news for the club and the player that Messi can renew his contract," coach Pep Guardiola said.
"People go to the stadiums to see good football and the fact that Barca has some of the best players in the world like Messi is a privilege."
Manchester City end interest in Barca's Eto'o
Brazil regain FIFA top spot
Pele urges FIFA to bring in salary cap
'Barca move will make me happiest man alive'
Messi helps Barca win Spanish Super Cup