For Mr. Peña Nieto, it is a win he can claim as part of his legacy. For Mr. López Obrador, it means the process will close before his Dec. 1 inauguration. That frees him from messy negotiations at the start of his administration and allows him to turn his attention to Mexico’s limping economy.

Since Nafta went into effect almost a quarter century ago, it has created a booming export economy driven by foreign investors who built factories across central and northern Mexico to supply the North American market. Last year, Mexico exported almost $410 billion worth of goods, more than 80 percent of that to the United States and Canada.

[Alan Rappeport, a Times reporter, answered questions about the new trade deal between the U.S., Mexico and Canada.]

But at the same time, Nafta displaced millions of small farmers and local manufacturers. Successive governments have failed to come up with development policies to reincorporate them and stimulate the rest of Mexico’s economy.

The result is that overall poverty rates have barely budged in Mexico under Nafta and economic growth per capita has lagged behind almost every other country in Latin America — just 1.2 percent on average from 1996 to 2015, according to Santiago Levy, a Mexican economist who is vice president at the Inter-American Development Bank.

Mr. López Obrador, a former mayor of Mexico City, campaigned on restoring the forgotten sectors of the economy, particularly in Mexico’s underdeveloped south. Although he was once a fiery opponent of Mexico’s market reforms, he has changed his rhetoric against free trade, arguing instead that Nafta should be improved to benefit Mexicans, rather than overturned.