Canada and the United States reached a deal Sunday night for Canada to stay in a free trade pact with the U.S. and Mexico.

U.S. Trade Representative Robert Lighthizer and Canadian Foreign Affairs Minister Chrystia Freeland announced the deal in a joint statement late Sunday. They say the newly named the United States-Mexico-Canada Agreement, or USMCA, will result in freer markets and fairer trade.

The agreement preserved a NAFTA dispute-resolution process that the U.S. wanted to jettison, the official told The Associated Press ahead of an official announcement. The official was not authorized to speak publicly and requested anonymity.

The agreement also exempts tariffs on 2.6 million cars. On dairy the official said Canada essentially gave the U.S. the same access it offered in the Trans Pacific Partnership trade agreement that President Donald Trump rejected.

"It's a good day for Canada," Prime Minister Justin Trudeau said as he left his office. Trudeau said he would have more to say Monday.

"It is a good night for Mexico, and for North America," Mexican Foreign Minister Luis Videgaray tweeted.

"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," the joint statement said. "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."

The U.S. and Canada were under pressure to reach a deal by midnight Sunday, when the U.S. must make public the full text of the agreement with Mexico.

Canada, the United States' No. 2 trading partner, was left out when the U.S. and Mexico reached an agreement last month to revamp the North American Free Trade Agreement.

The Trump administration officially notified Congress of the U.S.-Mexico trade agreement on Aug. 31. That started a 90-day clock that would let outgoing Mexican President Enrique Pena Nieto sign the new pact before he leaves office Dec. 1.

Mexico's economics ministry said in a tweet earlier Sunday that the text of the pact would be delivered to the Mexican Senate Sunday night, adding that "if there is agreement with Canada, the text will be trilateral. If there is not, it will be bilateral."

Trump had said he wanted to go ahead with a revamped NAFTA — with or without Canada. It was unclear, however, whether Trump had authority from Congress to pursue a revamped NAFTA with only Mexico, and some lawmakers said they wouldn't go along with a deal that left out Canada.

U.S.-Canada talks bogged down earlier this month, and most trade analysts expected the Sept. 30 deadline to come and go without Canada being reinstated. They suspected that Canada, which had said it wasn't bound by U.S. deadlines, was delaying the talks until after provincial elections Monday in Quebec, where support for Canadian dairy tariffs runs high.