Ecuador had twice come from behind at AT&T Stadium, goals from Angel Mena and Ayrton Preciado cancelling out efforts from Jonathan dos Santos and Luis Montes.
But Mexico found a late winner in their final game before the CONCACAF Gold Cup, Luis Rodriguez's 77th-minute volley settling the encounter.
Ecuador were almost gifted a dream start, Mexico defender Rodriguez clearing a ball into his own post after goalkeeper Guillermo Ochoa pushed away a cross from the right.
But that would be one of Ecuador's only chances in the first half as Mexico dominated.
Orbelin Pineda forced a save from Maximo Banguera after being played in by Dos Santos in the 18th minute, before later seeing a shot deflected wide.
Mexico continued to build into the encounter, Montes shooting over from range before Dos Santos' second international goal.
The LA Galaxy midfielder ran at the Ecuador defence before curling a beautiful effort from 25 yards into the bottom corner.
While Mexico went into the break ahead, their advantage disappeared just two minutes into the second half.
Mena, introduced at half-time, saw a 25-yard free-kick deflect off the wall, wrong-footing Ochoa and finding the back of the net.
Mexico restored their lead just after the hour-mark through Montes, who produced a moment of magic with a free-kick of his own.
After a clumsy handball led to the free-kick being awarded, Montes curled a strike over the wall and into the top corner from just outside the area.
However, Mexico's lead lasted just three minutes before Preciado headed in a Mena corner for his first international goal to bring Ecuador level once more.
The winner came through Rodriguez, who volleyed in Jesus Gallardo's delivery at the back post with his maiden strike at international level.
What does it mean? Mexico show why they are Gold Cup favourites
This win made it four from four for Martino since he took charge of Mexico in January. The victory over Ecuador added to wins against Chile, Paraguay and Venezuela, showing why Mexico go into the Gold Cup as favourites.
Dos Santos finds goal-scoring form for Mexico
It took Dos Santos 40 games to score his first international goal, but his effort against Ecuador marked his second in as many Mexico outings. It was a fine strike from distance, adding another element to Mexico that Martino will surely find useful in the future.
More injury woes for Mexico
Just days after Edson Alvarez was hurt against Venezuela, there was another injury worry for Mexico. Hector Moreno came off in the first half with a suspected muscle injury, adding another unwanted concern for Martino.
Mexico begin their Gold Cup campaign against Cuba on Saturday, while Ecuador face Uruguay in their Copa America opener on June 16.