Despite hitting the post twice from free kicks, Messi finally curled his third attempt past Panama keeper Jose Carlos Guerra in the 89th minute, at the Monumental Stadium.
"We said that we were going to give it all for this trophy," the seven-time Balon d’or said.
The win over Panama was Argentina's first match since defeating France in Qatar last December, with Thiago Almada opening the scoring in the second half before Messi added his historic goal shortly before the final whistle.
He celebrated his 700th career club goal just last month and now joins Cristiano Ronaldo as only the second man ever to reach the 800 career-goal landmark, according to the International Federation of Football History & Statistics (IFFHS).
However, there is some dispute over the classification of "official" goals scored in "official" competitions, with Brazilian great Pele claiming to have scored over 1,000 goals in his career.
Messi, who spent 17 years with Barcelona, scoring a club-record 672 goals in 778 appearances, has also set a La Liga record with 474 goals.
"Eternal gratitude to these players. Football belongs to them, and without them we wouldn't have won the World Cup,” he emotionally stated.
The full World Cup squad from Qatar attended the match and took pictures with the World Cup trophy before kick-off.
Messi, along with other players and the manager, brought their families to the stadium, adding a personal touch to the historic night.