Lionel Messi will end his 20-year career with Barcelona after the Argentine superstar failed to reach agreement on a new deal with the club, the Spanish giants announced on Thursday.

"Although an agreement has been reached between FC Barcelona and Leo Messi it cannot be formalised due to economic and structural obstacles," said a statement from the club.

"Faced with this situation, Lionel Messi will not remain linked to Barcelona. Both sides deeply regret that the wishes of both the player and the club cannot come true."

Lionel Messi is leaving Barcelona Lionel Messi is leaving Barcelona Photo: AFP / JORGE GUERRERO

Thursday's stunning announcement marked a new turnaround in a long-running saga where Barcelona had appeared certain to keep Messi, widely regarded as one of the greatest players of all time.

He had tried to leave last August as a free agent but the expectation was that he would remain with the Spanish giants for another five years, until 2026 when he would be 39.

The 34-year-old signed his first contract with Barcelona in 2000 on a napkin when he was just 13.

However, he had been a free agent since June 30 when his old agreement expired.