MEXICO CITY — Two years ago, as negotiators from Mexico, Canada and the United States were beginning to overhaul the North American Free Trade Agreement, Luis Rossano had a choice.

The 38-year-old engineer could expand his Mexican company, a thriving business producing high-tech car parts and medical devices in the southern city of Puebla.

Or he could take his plans to Europe.

“You have to decide: What is your legacy?” he said.

The entrepreneur bet on his homeland, doubling investment in the firm. But what followed, he said, were months of “convulsion.” No one knew how Mexican manufacturing would be affected by the trade talks. That question exacerbated the economic uncertainty resulting from Mexico’s election of its first leftist president in decades.

Mexico’s politicians and business community breathed a sigh of relief last week that the country would maintain its free-trade system with the United States, its No. 1 trade partner.

“Every last one of us wanted an agreement,” Rossano said.

That’s not to say the country was thrilled with all of the changes in the new U.S.-Mexico-Canada Agreement, or USMCA. Mexico’s flourishing auto industry will face new limits. Some executives were nervous about toughened enforcement of labor rights.

But at least there was an accord.

“Mission accomplished,” Foreign Minister Marcelo Ebrard said Tuesday.

Eugenio Salinas, president of the Foreign Trade Committee of Concamin, the Mexican industrial body, said “the level of uncertainty has had more effect than anything that came out of the negotiations.”

It’s hard to overstate the importance of U.S. trade to Mexico. About 80 percent of Mexican exports go to its northern neighbor.

Foreign investment is crucial. Mexico has one of the lowest rates of public investment in Latin America — most of the investment by far “is done by the private sector,” Finance Minister Arturo Herrera noted at an Atlantic Council event in October. Mexican officials hope to see a windfall after the treaty is ratified.

The Mexican peso edged up Wednesday for the sixth straight day, as reports emerged of an agreement on the trade pact.

For Rossano, the decision to bet on Mexico paid off. His 130-employee firm, Blue Quark Group, manufactures auto parts such as door lock systems for U.S. and European carmakers, as well as medical products such as an artificial heart. Sales have tripled since early 2018, he said, but investors have been cautious.

“I could see there was a period of waiting” for the treaty provisions to be clarified, said the entrepreneur, who served on a panel of business executives that advised the Mexican government on the talks.

The uncertainty was especially intense for the auto sector, one of Mexico’s biggest and most important industries. The Trump administration was eager to shift more factory jobs back to the United States. In the end, the three countries agreed that at least 40 percent of each car’s content must be produced by employees making $16 an hour or more to qualify for duty-free trade.

That will be a big change for Mexico, where auto-assembly workers on average earn $7.34 an hour, and auto-parts workers make $3.41 an hour, according to government statistics from 2017.

Another major concession involved labor protections. U.S. unions — and their Democratic supporters in Congress — were unhappy that Mexican unions are largely controlled by politicians and business executives, who keep a lid on wages.

Mexican legislators passed a law this year guaranteeing workers’ rights to approve contracts and choose union leaders by secret ballot. In recent weeks, Mexico’s negotiating team faced further pressure on labor provisions, but it rejected a proposal to allow U.S. inspectors to visit to guarantee enforcement of the measures, saying it would violate the country’s sovereignty.

“The idea of the inspectors was ruled out,” said Mexico’s chief negotiator, JesĂşs Seade.

Still, Mexico agreed to a dispute-resolution mechanism under which U.S. and other foreign experts could travel to the country to check on possible violations.

While Mexicans chafed at President Trump’s frequent threats to tear up NAFTA, President AndrĂ©s Manuel LĂłpez Obrador thanked him Tuesday for his help during the negotiations.

“Without his cooperation, it wouldn’t have been possible to reach this accord,” he said. Mexico, which alone among the three countries ratified the initial USMCA negotiated last year, approved the new changes on Thursday night.

LĂłpez Obrador, a onetime critic of NAFTA, supported the negotiations to redo the treaty, which were largely carried out before he took office a year ago. He is eager to inject life into the moribund economy, which failed to grow this year.

Hanging over the talks was concern about Trump’s pattern of trade fights around the world.

With the Republican facing a reelection campaign next year, “it seemed like a good idea to have the treaty wrapped up,” Rossano said.