The US and Canada came to an agreement Sunday to tweak key pieces of the North American Free Trade Agreement, known as NAFTA.

The US-Canada deal follows a separate agreement between the US and Mexico reached in August.

The two deals will pave the way for a full overhaul of the 25-year-old NAFTA deal.

President Donald Trump long promised to renegotiate or rip up NAFTA.

Trade negotiators for the US and Canada on Sunday evening put the finishing touches on a deal to reshape the 25-year-old North American Free Trade Agreement, known as NAFTA, sealing the largest trade-deal rewrite of President Donald Trump's tenure.

The agreement came just hours before a deadline set by the Trump administration, will pave the way for a vote in Congress to approve the deal after more than a year of negotiations among the US, Canada, and Mexico over the trilateral agreement.

A senior Trump administration official said Sunday night that the new deal will be renamed the USMCA: the US-Canada-Mexico Agreement. Trump has publicly groaned about NAFTA's name.

"Today, Canada and the United States reached an agreement, alongside Mexico, on a new, modernized trade agreement for the 21st Century: the United States-Mexico-Canada Agreement (USMCA)," the US and Canada said in a joint statement.

The statement went on: "USMCA will give our workers, farmers, ranchers and businesses a high-standard trade agreement that will result in freer markets, fairer trade and robust economic growth in our region. It will strengthen the middle class, and create good, well-paying jobs and new opportunities for the nearly half billion people who call North America home."

Canadian Prime Minister Justin Trudeau said that it was a "good day for Canada" when leaving his office on Sunday.

Negotiators for the US and Canada were able to overcome major sticking points between the two countries, including Canada's protection of its dairy market and a system for settling trade disputes.

Here's a rundown of where the two sides came out on a few of the major issues:

Dairy: Canada will allow American farmers more access to its dairy market, raising quotas on the amount of US dairy that can come into the country and eliminating a pricing system that made it more difficult for US farmers to enter the market. Canada will continue to impose severe tariffs on any US dairy that exceeds the quota. The access level is reportedly identical to what Canada agreed to give up as part of the Trans-Pacific Partnership (TPP), out of which Trump pulled the US early in his tenure.

Dispute resolution: Chapter 19, an extrajudicial trade dispute system that allows NAFTA members to bring grievances against other members over allegedly unfair trade practices, will remain in place as it is under the current NAFTA. The preservation of Chapter 19 was a big goal of the Canadian negotiators. According to senior Trump administration officials, Chapter 11 — which allows investors to bring disputes against other NAFTA member governments — will be phased out with Canada, a key goal for the US.

Tariffs: Canada received some assurances that any future tariffs on imported cars and auto parts will not hit the country. There was no formal agreement on the US's existing steel and aluminum tariffs, according to a senior Trump administration official.

In addition, Canada joined on to updated agreement made between the US and Mexico on a six-year review period for NAFTA and updates on intellectual property treatment.

The dairy issue was a longtime target for Trump, who insisted that the high protective barriers for US dairy farmers trying to export to Canada were unfair.

Canada, meanwhile, wanted to maintain Chapter 19, a key element of NAFTA that allowed countries to bring a grievance against another NAFTA member regarding unfair trade practices or tariffs. The procedure was essentially a fast-track version of the World Trade Organization's dispute settlements but only applied to the three NAFTA members.

The agreement also comes after the US and Mexico came to a separate deal that strengthened rules around auto production in August. The Trump administration repeatedly threatened to move forward with the bilateral deal, excluding Canada.

(Read more: Here are all the details of the US-Mexico trade agreement»)

Deadline day — and where we go from here

The new NAFTA deal also came on the last day before a Trump-imposed deadline to reach an agreement. Trump is renegotiating NAFTA under what is known as Trade Promotion Authority. While TPA gives Trump the ability to send a deal to Congress for a simple majority vote, it also includes a statutory 60-day notification period.

The timeline of the notification period has provided urgency to spearhead a NAFTA deal through Congress and onto the desk of Mexican President Enrique Peña Nieto before President-Elect Andrés Manuel López Obrador takes office in December. While López Obrador did have representatives present during the US-Mexico talks, US and Mexican officials worried about about possible political upheaval around the changeover.

The US-Canada deal appears to be a victory for both sides. On one hand, Trump is able to fulfill a rewrite of a deal he once called the "worst trade deal ever made." On the other, Trudeau preserves a deal that Trump repeatedly threatened to scrap altogether.

The deal must clear a series of procedural hurdles to get to Congress for a vote, which is unlikely to come before 2019.

In addition to opening the door for a NAFTA rewrite, the deal could also ease trade tensions between the US and Canada over Trump's steel and aluminum tariffs.

Trump announced that the US would impose a 25% tariff on imports of Canadian steel and a 10% tariff on aluminum in June, which in turn prompted Canada to respond with retaliatory tariffs on a slew of US products in July.