OTTAWA/WASHINGTON (Reuters) - The United States and Canada forged a last-gasp deal on Sunday to salvage NAFTA as a trilateral pact with Mexico, rescuing a three-country, $1.2 trillion open-trade zone that had been about to collapse after nearly a quarter century.

In a big victory for his agenda to shake-up an era of global free trade that many associate with the signing of NAFTA in 1994, President Donald Trump coerced Canada and Mexico to accept more restrictive commerce with their main export partner.

Trump’s primary objective in reworking NAFTA was to bring down U.S. trade deficits, a goal he has also pursued with China, by imposing hundreds of billions of dollars in tariffs on imported goods from the Asian giant.

While the new United States-Mexico-Canada Agreement (USMCA) avoids tariffs, it will make it harder for global auto makers to build cars cheaply in Mexico and is aimed at bringing more jobs into the United States.

Since talks began more than a year ago, it was clear Canada and Mexico would have to make concessions in the face of Trump’s threats to tear up NAFTA and relief was palpable in both countries on Sunday that the deal was largely intact and had not fractured supply chains between weaker bilateral agreements.

“It’s a good day for Canada,” Prime Minister Justin Trudeau told reporters after a late-night cabinet meeting to discuss the deal, which triggered a jump in global financial markets.

In a joint statement, Canada and the United States said it would “result in freer markets, fairer trade and robust economic growth in our region”.

Negotiators worked frantically ahead of a midnight ET (0400 GMT) U.S. imposed deadline to settle differences, with both sides making concessions to seal the deal. The United States and Mexico had already clinched a bilateral agreement in August.

“It’s a great win for the president and a validation for his strategy in the area of international trade,” a senior administration official told reporters.

Trump has approved the deal with Canada, a source familiar with the decision said. U.S. officials intend to sign the agreement with Canada and Mexico at the end of November, after which it would be submitted to the U.S. Congress for approval, a senior U.S. official said.

COST FOR CANADA

The deal will preserve a trade dispute settlement mechanism that Canada fought hard to maintain to protect its lumber industry and other sectors from U.S. anti-dumping tariffs, U.S. and Canadian officials said.

But it came at a cost.

Slideshow ( 4 images )

Canada has agreed to provide U.S. dairy farmers access to about 3.5 percent of its approximately $16 billion annual domestic dairy market. Although Canadian sources said its government was prepared to offer compensation, dairy farmers reacted angrily.

“We fail to see how this deal can be good for the 220,000 Canadian families that depend on dairy for their livelihood.” Pierre Lampron, president of Dairy Farmers of Canada, said in a statement.

“This has happened, despite assurances that our government would not sign a bad deal for Canadians.”

Slideshow ( 4 images )

The deal also requires a higher proportion of the parts in a car to be made in areas of North America paying at least $16 an hour, a rule aimed at shifting jobs from Mexico.

Canada and Mexico each agreed to a quota of 2.6 million passenger vehicles exported to the United States in the event that Trump imposes 25 percent global autos tariffs on national security grounds.

The quota would allow for significant growth in tariff-free automotive exports from Canada above current production levels of about 2 million units, safeguarding Canadian plants. It is also well above the 1.8 million cars and SUVs Mexico sent north last year.

But the deal failed to resolve U.S. tariffs on Canada’s steel and aluminum exports.

The Trump administration had threatened to proceed with a Mexico-only trade pact as U.S. talks with Canada foundered.

“It’s a good night for Mexico, and for North America,” Mexican Foreign Secretary Luis Videgaray said.

The news delighted financial markets that had fretted for months about the potential economic damage if NAFTA blew up.

U.S. stock index futures rose, with S&P 500 Index e-mini futures up more than 0.5 percent, suggesting the benchmark index would open near a record on Monday.

The Canadian dollar surged to its highest since May against the U.S. dollar, gaining around 0.5 percent. The Mexican peso gained 0.8 percent to its highest against the greenback since early August.[MKTS/GLOB]

“Though markets were already anticipating an agreement, one source of worry will be swept away if a deal is made,” Yukio Ishizuki, senior currency strategist at Daiwa Securities in Tokyo, said.

“That will lead to a rise in trust in the U.S. economy, so it’s easy for risk sentiment to improve.”