The Argentina star and his father were found guilty of evading tax on income from image rights by a Catalonian court in 2016 and were sentenced to 21 months in prison, although this was changed to a fine a year later.
Messi has now revealed he felt so "mistreated" during the investigation that he considered quitting Barcelona so he could get out of the country, but he thinks other clubs were put off making official offers as they knew he was at heart a one-club man.
"In the years 2012, 2013 and 2014, I had a tough time," Messi told RAC1. "Yes, for the issue with the Hacienda [Spain's state tax agency]. It was really difficult for me and my family because people didn't really know what was happening. They heard things and they opined. A part of the press did the same, too.
"I think I was the first [footballer to be investigated by the Hacienda] and for that reason it was all so hard. My kids were little.
"At that time, I honestly thought about leaving. Not because I wanted to leave Barca, but to leave Spain because I felt mistreated and I didn't want to be here. I had many doors open but never anything official because everyone knew my desire was to continue but it was something which went beyond my feelings towards Barca."
Question marks over Messi's future appeared again this September when he told Sport that, although he did not want to leave Camp Nou, he was eager to be part of a "winning team".
It was suggested the 32-year-old was referring to recent Champions League frustrations, with Barca's last triumph coming in 2015 and their past two campaigns ending in humiliating defeats to Roma and Liverpool.
However, Messi has made it clear he wants to end his career with Barcelona and may even pass on his dream of playing for boyhood club Newell's Old Boys in Argentina before he retires as he does not want to uproot his family.
"It's true we struggled to get started this season, but we have a good squad with great players to be able to win everything," Messi said.
"We are here to win and to win titles. In recent years we have been close. In the last two years, it was our fault for the way we got knocked out. It wasn't the project or the coach. We have a great squad to be able to win everything.
"And obviously, if they want me, I'm delighted [to stay]. I will repeat: my idea is always to stay here. My idea and my family's idea is to end my career here."
He said that he has "always dreamed" of playing for Newell's.
"But sometimes you have to think more about the family than what you want," Messi said. "The family is the most important thing."
Messi also hopes to see former team-mate Xavi return to Barca as a coach, even if that happens after he has retired. Xavi is currently coaching Qatari side Al Sadd.
"He's in training and at some point he'll come back here," Messi added. "I have a feeling he'll be similar to [Pep] Guardiola. I don't know if I'll experience it as a player, of course."