FC Dallas led 4-2 with 10 minutes left but two late goals took the game to a penalty shootout.
Miami won the shootout 5-3 at Toyota Stadium in Frisco, Texas.
"Being 4-2 down in the 80th minute and then coming back, we are very happy with the result," Miami manager Gerardo Martino said.
"But the fact that we have gone through shouldn't let us lose sight of the things that we have to improve."
Miami were winless in 11 before Messi's arrival but have now won four in a row.
The former Barcelona and Paris St-Germain forward opened the scoring after six minutes, sweeping a curling shot inside the near post from outside the penalty area, but Dallas were 3-1 ahead with just over an hour played.
Each time Lionel Messi lined up for a free-kick in his first away game for Inter Miami, thousands of fans packed into a stadium in the searing Texas heat stood and held up their cell phones, ready to record. They all successfully captured footage of history repeating itself.
Messi scored another mesmerising free-kick in his third consecutive two-goal game, drawing Inter Miami level before they snatched victory over FC Dallas on penalties to move into the Leagues Cup quarter-final.
Messi’s goal in the 85th minute to square things at 4-4 was reminiscent of the game-winner from his Inter Miami debut, both free-kicks from just outside the area in the waning moments, both sneaking past the goalkeeper into the upper corner of the net.
While Messi made no stumbles and few errors Sunday night, the same can't be said of many of his Inter Miami teammates. FCD headed into the locker room with a 2-1 lead after goals from Facundo Quignon and Bernard Kamungo.
FCD extended that lead to 3-1 in the 63rd minute when Alan Velasco's free kick from the left wing bounced through traffic and into the Inter Miami net. And while Inter pulled back a goal shortly after, it again fell victim to its own sloppy play as forward Robert Taylor put the ball into his own net in the 68th minute.
Inter Miami will host either Houston Dynamo or Charlotte FC at DRV PNK Stadium in the quarterfinals.
The Leagues Cup is joint competition organized by the top-tier soccer competitions in the US and Mexico which features every club in the top two leagues in North America.
The winner of the tournament qualifies directly to Concacaf Champions League round of 16.
Read more
England goalkeeper Mary Earps Liverpool vs. Darmstadt 98: Liverpool win 3-1Sarah H
Also on site :
- Bomb alert on Ryanair plane carrying 170 passengers as holiday flight lands in Belgium & ‘cordon set up’
- UnitedHealth Group CEO steps down; suspends 2025 outlook on higher-than-expected medical costs
- Toyota’s legendary look returns to where it all began.