TORONTO — More than a celebration, it ended with a huge sigh of relief.
Canadians awoke on Monday to the news of a new trade deal with the United States, its largest trading partner, and more important, a reprieve from the threat of crippling auto tariffs that President Trump had been holding over the country for months.
Prime Minister Justin Trudeau of Canada came away with a few items considered sacred for his nation’s economic security: a dispute resolution system for companies that feel unjustly targeted with taxes and a distant expiration date to the agreement.
In exchange, Canada promised to crack open its long-protected dairy market — the target of Mr. Trump’s Twitter attacks and rally tirades for months — to American competition, a concession that drew immediate anger from politicians in Quebec, home to nearly half of the country’s 11,200 dairy farms.
At a news conference in Ottawa on Monday, Mr. Trudeau called the agreement “a good deal,” although he acknowledged the trade-offs.
“Like any important negotiation, we had to make compromises,” he said, speaking in French. But, he added, “today is a good day for Canada.”
The agreement does not eliminate the steep tariffs on steel and aluminum that Mr. Trump imposed in the spring. Instead, Mr. Trudeau said his country would continue to negotiate for their removal.
“The great failure of this trade deal was not negotiating an end to the steel and aluminum tariffs,” said Philip Cross, the former chief economic analyst at Statistics Canada, a government agency, because it tacitly left the door open to Mr. Trump to use the same national protection justification to lay more tariffs in the future, regardless of any trade deal.
“He can invoke national security under this deal and slap tariffs presumably on anything he wants,” said Mr. Cross, who is now a senior fellow at the Macdonald-Laurier Institute, a conservative research group based in Ottawa. “I’m not sure we got the guaranteed secure access to the U.S. that free trade was supposed to give us.”
Still, several economists said that although the deal would most likely not boost the Canadian economy, it was unlikely to hurt it much, either.
The concessions on dairy enraged politicians in Quebec, the country’s second-largest province and the center of the dairy industry. All four party leaders vying for votes in the provincial election on Monday rejected the Canadian government’s promise of compensation for farmers.
“It is an expression of the systematic injustice that Quebec is suffering within Canada,” the leader of the separatist Parti Québécois, Jean-François Lisée, told reporters.
During much of the negotiations, Mr. Trump had threatened to impose 25 percent tariffs on Canadian autos and auto parts crossing into the United States, which would have crippled the Ontario economy, putting an estimated 250,000 people out of work, according to one forecast. It would also have become a potent issue in Mr. Trudeau’s re-election campaign next year.
The new agreement — which renames the North American Free Trade Agreement as the United States-Mexico-Canada Agreement — neutralizes that threat by effectively exempting Canada’s exports to the United States. By requiring 40 percent of auto parts to come from so-called “high wage factories,” it could even give unionized Canadian auto manufacturers a leg-up.
“I would argue we are in better shape today than we’ve been in the last 24 years,” Jerry Dias, the head of Canada’s largest private sector union, Unifor, said on a morning Canadian Broadcasting Corporation radio show. “So I’m absolutely thrilled with where we ended up.”
He added: “Look, we hung tough right to the bitter end. We got what we needed. We didn’t fold in the areas that the U.S. wanted us to fold in, so we’re in pretty good shape today.”
Compared with President Trump, who triumphantly claimed the deal would see “cash and jobs pouring into the United States and into North America,” Mr. Trudeau was gracious and understated during his news conference.
For him, the deal was more about shoring up the Canadian economy than expanding it. “We preserved the most important parts of Nafta,’’ Mr. Trudeau said.
The agreement was good for the economy, good for workers, he said, and made North America “a much more stable place than it was yesterday.”
Completing the deal capped what had been an exhausting and turbulent process for the prime minister who, with the election looming, had at times appeared vulnerable and stumbling beneath a shower of insults from Mr. Trump.
Many thought Mr. Trudeau was in an impossible position — trying to get a deal he could sell as good for his country, and maintaining his dignity when dealing with the unpredictable Mr. Trump.
The test for Mr. Trudeau, who faces an election next year, will be whether he can persuade voters that Nafta 2.0 is a “win-win-win,” as he has long assured them it would be.
“Justin Trudeau has to take the high ground on this fairly quickly,” said Shachi Kurl, the executive director of the Angus Reid Institute, a nonprofit polling organization based in Vancouver. “Can he sell the deal?”
Almost from the beginning of his candidacy for president, Mr. Trump has criticized Nafta, and especially the provisions relating to Canada — a drumbeat that has not let up.
That added additional drama to the negotiations, which Canadians have followed with the rapt attention normally reserved for hockey playoffs.
Despite harboring a deepening dislike for Mr. Trump, Canadians largely accept that the country cannot survive economically without its larger, more powerful neighbor. Almost three-quarters of Canada’s exports flow south across the border.
As negotiations reached their final stages last week, Canadians were riveted by the spectacle of the hearings for the nomination of a United States Supreme Court justice, which drowned out most trade news on Friday.
The polarization of American politics, the uncertainty of what kind of trade deal Congress would accept and how the midterm elections in the United States would change things has made most Canadians throw up their hands in exasperation.
Then there was Mr. Trump, who to Canadians seems immune to fact; approaches every deal as a tug-of-war; and has taken to publicly insulting the United States’ longest-standing ally and neighbor.
“He’s weaponized uncertainty,” said John Higginbotham, a senior fellow at Carleton University in Ottawa who was the second-highest-ranking Canadian diplomat in Washington for six years.
“You can’t call his bluff with impunity,” he added. “He’s not playacting, he’s a bit crazy. He is a bit crazy.”
Just last week, Mr. Trump said he did not like Canada’s representative — presumably referring to Foreign Minister Chrystia Freeland — “very much,” and that he had purposefully snubbed Mr. Trudeau, by refusing to meet with him at the United Nations. (Mr. Trudeau’s office said no request for a meeting was ever made.)
Nafta negotiations began more than a year ago, with Mr. Trudeau saying he wanted an agreement that would be good for Canadian workers but also include climate change provisions and new chapters on gender and indigenous rights.
Mr. Trudeau deployed an army of charmers across the border to build alliances with people around Mr. Trump.
Known as the doughnut strategy, the campaign seemed to be working. But in May, two days after a deal on Nafta looked close, the Trump administration announced it would proceed with steep tariffs on steel and aluminum.
The Canadian government countered with tariffs on $12.6 billion of American imports.
Since then, the relationship between the two countries — and the two leaders — has further soured.
In June, at the end of a two-day Group of 7 summit meeting in Charlevoix, Quebec, Mr. Trudeau said at a news conference that Canada would not be bullied on trade.
“As Canadians,” he said, “we are polite, we’re reasonable, but also we will not be pushed around.”
Mr. Trump erupted in anger from Air Force One, en route to his summit meeting with the North Korean leader Kim Jong-un. He wrote on Twitter that Mr. Trudeau was “very dishonest and weak” and accused him of making false statements.
Canadians rose up in defense of Mr. Trudeau, whose approval rating surged to 70 percent in a number of polls. Even his political enemies lined up behind him.
Canadians canceled trips across the border and began personal boycotts of American goods in protest.
Then, in late August, Mr. Trudeau received another rude shock when the American and Mexican presidents signed a deal without him.
Some thought Mr. Trudeau was outmatched by Mr. Trump.
“There was some illusion that sending a couple progressive people from the prime minister’s office to see Ivanka, that would solve the problem,” said Mr. Higginbotham, referring to the president’s elder daughter.
But many Canadians believe the American administration has not been negotiating in good faith — a position supported by Mr. Trump telling Bloomberg last month that any deal with Canada would be “totally on our terms.”
And most agreed that Mr. Trudeau and his foreign minister, Ms. Freeland, had been put in tricky positions.
“I’m not sure they had a lot of choice,” said Don Campbell, a former Canadian ambassador and high-level government official who was involved in setting up the first iteration of Nafta.
“They are dealing with an unprecedented situation, with a president who is not rational or consistent in his approach, who disregards facts and who does not tell the truth,” he said.