Two-time world champions Argentina were in danger of missing the showpiece tournament for the first time since 1970, having dropped to sixth and outside of the qualifying positions following three consecutive draws.
Those fears became real when Ecuador broke the deadlock after just 38 seconds via Romario Ibarra at altitude in Quito on Tuesday.
But Argentina – who reportedly hired a sorcerer to help bring good energy to the team with their World Cup hopes on the line – fought back as captain and five-time Ballon d'Or winner Messi singlehandedly booked the country's ticket to Russia next year, becoming the first player to score 20 goals in CONMEBOL qualifying in the process.
Messi equalised expertly in the 12th minute after combining with Angel Di Maria and his thunderous effort nine minutes later completed the comeback and ensured Argentina led at the break, before he sealed the great escape with a glorious chip just past the hour-mark.
Like the goalless draw against Peru in Buenos Aires, there was only room for Juventus star Paulo Dybala and Inter captain Mauro Icardi on the bench. Jorge Sampaoli did make two changes, bringing in Eduardo Salvio and Enzo Perez for Alejandro Gomez and Ever Banega.
Ecuador were without Manchester United's Antonio Valencia and Michael Arroyo through suspension following last week's 2-1 loss in Chile. Jefferson Orejuela also dropped out as Pedro Velasco, Francisco Cevallos and Ibarra came into the line-up.
Argentina – who only required a win to claim at least fifth position and a play-off berth against New Zealand – could not have dreamed of a worse start in Quito after conceding in just the 38th second – their fastest goal conceded in World Cup qualifying history.
Fans barely had the chance to take their seats as Ibarra – making just his second international appearance – played a neat headed one-two with Ordonez on the edge of the area before firing past goalkeeper Sergio Romero.
It left Argentina disjointed and void of any structure as Ecuador oozed confidence on home soil but Messi popped up to restore hope and ease fears for the visitors in the 12th minute.
Some sublime play between Messi and Di Maria carved up Ecuador as the former surged into the penalty area after playing the ball out left to the Paris Saint-Germain winger before side-footing past Maximo Banguera.
That allowed Argentina to wrestle back the ascendency and with Messi at the forefront, it was not long before they hit the front thanks to their captain nine minutes later.
Messi hunted down the ball on the edge of the box and dispossessed his opponent as he rifled a shot into the roof of the net.
He almost turned provider for Di Maria just past the half-hour mark, but the winger's close-range effort was saved by Banguera.
The second half was more subdued as Argentina protected their priceless advantage, though Messi was still front and centre as he completed his three-goal haul in beautiful fashion.
Messi pounced on a loose ball outside the box and he ducked and weaved past opponents, using Dario Benedetto as a decoy before darting to the left and chipping over Banguera majestically.