WASHINGTON — President Donald Trump said on Thursday he pulled back from the brink of killing the 23-year-old trade pact with Canada and Mexico after requests from their leaders and expressed optimism about winning better U.S. terms in a renegotiated deal.

Trump, during a White House appearance with Argentine President Mauricio Macri, said terminating the North American Free Trade Agreement, a pact he has long condemned as unfair to the United States, “would be a pretty big shock to the system,” though he was planning to do so within two or three days.

Hours after White House officials disclosed on Wednesday that Trump and his advisers had been considering an executive order to withdraw from NAFTA, he said he received telephone calls from Mexican President Enrique Pena Nieto and Canadian Prime Minister Justin Trudeau.

“They asked me to renegotiate. I will,” Trump said. “And I think we’ll be successful in the renegotiation, which frankly would be good because it would be simpler” than killing NAFTA.

Trudeau said he had warned Trump of the disruption that pulling out of NAFTA would cause. Mexico’s foreign minister said a good outcome for all three countries was possible under a new accord.

News of the possible U.S. pullout from NAFTA rattled financial markets on Wednesday. Relative calm returned on Thursday after Trump’s comments, and the Mexican peso strengthened 0.86 percent against the U.S. dollar while the Canadian dollar was flat versus the greenback.

Mexico, Canada and the United States form one of the world’s biggest trading blocs, and trade disruptions among them could adversely affect agricultural, automotive, energy and other sectors in all three countries. NAFTA erased most trade and tariff barriers between the neighbors, but Trump and other critics have blamed it for deep U.S. job cuts.

Trump campaigned for president last year on a pledge to pull out of NAFTA if he could not renegotiate better terms. The United States went from running a small-goods trade surplus with Mexico in the early 1990s to a $63 billion deficit in 2016. On Thursday he said NAFTA had been “horrible” for the United States but very good for Canada and Mexico.

“If I’m unable to make a fair deal … for the United States, meaning a fair deal for our workers and our companies, I will terminate NAFTA. But we’re going to give renegotiation a good strong show,” Trump said.

Trudeau, speaking at a news conference in Saskatchewan, said he had urged Trump not to withdraw from the trade pact and warned that doing so “would cause a lot of short- and medium-term pain.”

“That’s not something that either one of us would want, so we agreed that we could sit down and get to work on looking at ways to improve NAFTA,” Trudeau said.

Canada sends 75 percent of all its exports to the United States. On Tuesday, Trump said he did not fear a trade war with Canada, a day after his administration moved to impose tariffs on Canadian lumber.

In Mexico City, Mexican Foreign Minister Luis Videgaray said Pena Nieto had called Trump on Wednesday and spoke with him for about 20 minutes in a conversation focused exclusively on the looming talks over NAFTA’s “renegotiation and modernization.”

Trump has accused Mexico of luring away American factories and jobs with cheap labor and other advantages enabled by NAFTA. During the presidential campaign he accused Mexico of sending rapists and criminals into the United States, and as president plans a U.S.-Mexico border wall.

“I believe that all the conditions to reach a good negotiation exist, that will suit Mexico … and that is also good for the region, for both Canada and the United States,” Videgaray told local broadcaster Televisa.

Trump’s scorn toward multinational trade deals, part of his nationalist political message, appeals to Americans who feel such pacts have cost Americans jobs. He has said businesses that choose to move plants outside the country would pay a price.

Trump made pulling out of the 12-nation Trans-Pacific Partnership, negotiated by his Democratic predecessor Barack Obama, one of his first major acts after becoming president in January.

Several agriculture lobby groups in Washington were told U.S Agriculture Secretary Sonny Perdue, confirmed by the Senate on Monday, met with Trump on Wednesday evening to dissuade him from withdrawing from NAFTA.

American Soybean Association President Ron Moore said, “When you’re talking about $3 billion in soybean exports a year, any threats to withdraw from agreements and walk away from markets makes farmers extremely nervous.”

Formal NAFTA talks likely will not get started until August. The U.S. trade representative’s office must first send Congress a notice that starts a 90-day consultation period preceding any negotiations. A USTR spokeswoman said the notice would not be sent until the Senate confirms Trump’s nominee for trade representative, Robert Lighthizer.