The eight-time Ballon d'Or winner, who announced his retirement from international football after defeat in the World Cup final, was invited to participate in the friendly to celebrate his career, with all his teammates from Argentina's triumphant 2022 World Cup squad invited.
The 39-year-old ends his international career with 208 senior caps, the most of any player in the team's history, with his 126 goals for Argentina also a record. He is the only player to start three World Cup finals.
"It was a source of great pride to wear this jersey for over 20 years," Messi told the crowd after fulltime.
"I never stopped fighting, never stopped giving my all. I would love to keep coming back forever, because playing for the Argentine national team is the most beautiful thing that can happen to you."
Messi had been threatened to be upstaged by another departing Argentina player, 38-year-old centre-back Nicolas Otamendi, when the latter opened the scoring shortly after halftime, with Nico Paz adding a second.
Inevitably Messi had the final word, firing a penalty into the roof of the net with 20 minutes remaining to sign off his remarkable international career in style.
Messi was denied by Benin goalkeeper Marcel Dandjinou after seven minutes before the visitors almost took a shock lead when Aiyegun Tosin volleyed wide.
Messi turned a cross narrowly wide midway through the first half and was off target again in the 33rd minute.
Emi Martinez denied Junior Olaitan before the break and three minutes after the interval Otamendi fired home after Benin failed to clear a Messi corner.
Dandjinou kept out an Enzo Fernandez header before Paz doubled Argentina's lead from the edge of the area after 61 minutes.
Messi's moment came 10 minutes later when Tamimou Ouorou's clumsy challenge on Agustin Giay resulted in a spot kick, which the Inter Miami forward blasted into the top corner for his last international goal.
Dandjinou denied Leonel Flores late on before Messi bid the crowd an emotional goodbye at fulltime.
"I am proud to be Argentine and to have been able to fulfil this dream with all of you," Messi concluded, before taking a solitary victory lap.
"I'm going to miss you all. Now I'll be on your side, supporting the national team and the guys who come next.
"When we're united, we're stronger than anyone and can overcome anything. Tough times lie ahead, because what this group achieved won't be easy to repeat."
With the AP.