After twice hitting the post from free kicks, Messi curled his third try past Panama keeper Jose Carlos Guerra in the 89th minute to hit the 800 goal mark and send the sold-out crowd at Monumental Stadium into delirium.
"I want to thank you all for the love and recognition that you have been receiving, not only after the World Cup but also for the Copa America," Messi told the crowd after the match. "We said that we were going to give it all for this trophy."
The Argentine superstar came into the game needing just one goal to reach the milestone after scoring his 799th goal in PSG's Ligue 1 win over Nantes on Saturday.
The win over Panama came in Argentina's first match since beating France in Qatar last December. The team was roared on by the home supporters as Thiago Almada opened the scoring in the second half and Messi added his historic goal right before full-time.
The full squad from Qatar attended the match and took pictures in front of the World Cup trophy before kickoff, while Messi, manager Lionel Scaloni and others brought their families to the stadium.
A tearful Scaloni said after the match: "Eternal gratitude to these players. Football belongs to them, and without them we wouldn't have won the World Cup.
"Everyone who wears this shirt gives their all and sometimes the results don't come. But this time we got it and it's incredible."
According to the International Federation of Football History & Statistics (IFFHS), Messi is just the second man ever to reach the 800 career-goal landmark, after Cristiano Ronaldo.
The Portuguese star, 38, scored his 800th goal in December 2021.
However, there is some dispute between other sources due to historical inconsistencies in the classification of "official" goals scored in "official" competitions. Brazilian great Pele claims to have scored more than 1,000 goals during his career.
Messi, 35, spent the first 17 years of his senior career with boyhood club Barcelona, where he went on to score an incredible club-record 672 goals in 778 appearances.
His 474 LaLiga goals remains a record for Spain's top division.
Since leaving Barcelona due to the club's financial problems and joining PSG in the summer of 2021, Messi has scored 30 goals for the French champions.
The Rosario star has scored a further 98 goals internationally for Argentina, including seven goals in Qatar as he lifted the World Cup for the first time.
He has been named FIFA's best men's player a record seven times.