OTTAWA – Four hundred and ten days have passed since Canada entered into North American Free Trade Agreement renegotiations with the United States and Mexico.

Canadian officials have now reached a NAFTA deal before the U.S.-imposed midnight Sunday deadline. The deal still needs final approval and the text must be finalized.

Over the course of the talks there have been several moments where it seemed a deal was imminent. Just as many times, the prospect of ever coming to an agreement that all sides could live with seemed hard to envision.

Here’s a rundown of what we know, and how the talks arrived at this moment.

Canadian officials locked in talks

Since late Friday there have been strong indications that Ottawa was ready to make a deal in hopes of saving the three-way trade agreement. Mexico was set to release the text of its bilateral pact with the U.S. Friday evening, but agreed to hold off to give Canada more time to negotiate.

Saturday, Foreign Affairs Minister Chrystia Freeland left the United Nations where she was set to address the UN General Assembly, and returned to Parliament Hill, where sheand other senior officials, including Prime Minister Justin Trudeau, have been working towards a deal since.

The talks are said to include shoring up protection against the auto tariffs that Trump threatened again last weekat a wide-ranging press conference, should a deal not materialize.

These tariffs—which, if levied, are expected to be done using the same Section 232 national security argument as was used on the steel and aluminum tariffs—are something that Canada’s Ambassador to the United States David MacNaughton has said would “fundamentally change the relationship between Canada and the United States for a long time to come.”

In that fiery press conference last week, Trump cast serious doubt on the fate of NAFTA, insulting the Canadian negotiating team, and vowing that even if a trilateral deal is struck, it won’t be called NAFTA, because he’s “never liked it.”

These negotiations were first prompted by Trump’s belief that the deal as signed 24 years ago was unfair to the U.S., and upon his election he initiated the talks that have since become a key focus of Freeland’s tenure as foreign affairs minister and for the entire federal government, including high-level bureaucrats from various departments.

U.S.-Mexico have a deal

The U.S. and Mexico have already reached a consensus following bilateral negotiations.  Since their agreement was announced in late August, Freeland and theCanadian negotiating team have been back and forth to Washington, D.C. for discussions to try to maintain the trilateral agreement before the U.S. and Mexico embark on their own trade agreement.

After announcing the deal with Mexico, Trump said Canada had to come on board within a few days. That didn’t happen, and talks have continued.

That deadline was to inform U.S. Congress of the new trade pact, something that has to be done 90 days before the deal can be signed. Congress was informed, which triggered the current 30-day window to provide U.S. lawmakers with the text of the deal. The U.S. has indicated that it is prepared to move forward with the deal, whether it’s a bilateral or trilateral text they submit for Congress to review.

In a copy of the letter Trump sent to the Speaker of the House of Representatives and to the President of the Senate, Trump said he intended to initiate trade negotiations with both countries, and enter the agreement by the end of November 2018, saying that “dramatic progress” has been made related to several areas.

Among them, Trump includes: fairer market conditions for American farmers, tough environmental and labour rules, and enhanced innovation and intellectual property protections.

Sticking points and progressive chapters

At the start of the process, Canada announced its key objectives in the talks were to get a fair, modernized deal that included stronger labour and environmental protections, as well as entirely new “progressive” chapters on gender and Indigenous rights. It is unclear where those stand, with bigger sticking points dominating the discussions.

The main areas of contention that have arisen through the deliberations have been: rules of origin for autos, the Chapter 19 dispute resolution mechanism, more U.S. access to Canada’s supply managed dairy sector, the prospect of the deal including a sunset clause, and protecting Canadian cultural industries.

‘Moments of drama’

Over the course of the talks Canada predicted, and has experienced, as Freeland put it: “moments of drama.”

A few months into the talks, the signs weren’t good.

“I’m hearing that people are extremely worried about where this is going, and people use language behind the scenes like 'it looks like the Americans are driving towards a cliff on this, and Canada will have to follow' and we don’t want to see that," said member of Canada’s NAFTA Advisory Council Rona Ambrose on CTV’s Question Period back in October 2017.

At the time the Americans had just put demands on the table, including on auto and dairy, that Freeland called "unconventional" and "troubling" in the round four closing news conference. Days later, Trump’s pick for U.S. ambassador to Canada, Kelly Craft, was sworn in to her new post in Ottawa.

By January of this year, Freeland said Canada was preparing for the worst.

"Our approach from the start has been to hope for the best, but prepare for the worst, so Canada is prepared for every eventuality," she said at the Liberal cabinet retreat.

By June tensions seemed to have boiled over, with Trump leaving the G7 in Canada calling Trudeau “very dishonest and weak” just days after U.S. Secretary of Commerce Wilbur Ross announced the imposition of steel and aluminum tariffs on Canada and Canada announced its own dollar-for-dollar retaliatory tariffs on American-made steel, aluminum, and other goods.

These cross-border tariffs remain in place, and as of August they’d netted Canada nearly $300 million.

Earlier this month a top Republican in the House of Representatives issued a serious warning: patience and time is running out for Canada to come on board a revised trilateral North American trade deal.

This came just before Freeland’s latest round of high-level talks in D.C. where she raised some eyebrows for arriving at the Washington airport in a T-shirt from her kids that read: “Keep Calm and Negotiate NAFTA.”

Freeland was seen wearing that same shirt on Sunday in Ottawa, before a deal was reached.