The U.S. and Canada agreed to a trade deal that would preserve a three-way bloc with Mexico, setting the stage for their leaders to sign the accord by the end of November.

The three countries reached an agreement to replace the 24-year-old North American Free Trade Agreement, according to a joint statement from U.S. Trade Representative Robert Lighthizer and Canadian Foreign Affairs Minister Chrystia Freeland on Sunday. The new deal will be called the U.S.-Mexico-Canada Agreement, or USMCA.

The deal involves improved access to Canada’s dairy market for U.S. farmers, stronger intellectual property provisions, and tighter rules of origin for auto production, according to two senior Trump administration officials who spoke to reporters on a briefing call on condition of anonymity.

U.S. and Canadian negotiators have been working around the clock this weekend to make a Sunday midnight deadline that would allow the countries to sign the deal before Mexico’s outgoing President Enrique Pena Nieto leaves office on Nov. 30.

The Trump administration had already agreed last month to an updated pact with Mexico, increasing the pressure on Canada to make concessions to join the deal.

Lawmakers from the three countries still need to approve the pact. The new deal likely won’t be voted on by the U.S. Congress until 2019. The Democrats may take control of the House in midterm elections in November, which could undermine Trump’s ability to win approval.

Under U.S. trade law, the administration was required to publish the text by the end of September.

A revised Nafta would be a landmark for Trump, who has called the current deal a “disaster” and vowed to reduce America’s yawning trade deficit and revive manufacturing jobs. The president had threatened repeatedly to pull out of the pact, a scenario that business leaders warn would wreak havoc on their supply chains. In force since 1994, Nafta eliminated tariffs on most goods and governs more than $1 trillion in trade on the continent.