WASHINGTON — President Trump, in a sharp reversal, told a gathering of farm-state lawmakers and governors on Thursday morning that the United States was looking into rejoining a multicountry trade agreement known as the Trans-Pacific Partnership, a deal he pulled out of days after assuming the presidency.

Mr. Trump’s reconsideration of an agreement he once denounced as a “rape of our country” caught even his closest advisers by surprise and came as his administration faces stiff pushback from Republican lawmakers, farmers and other businesses concerned that the president’s threat of tariffs and other trade barriers will hurt them economically.

Larry Kudlow, Mr. Trump’s top economic adviser, said in an interview on Thursday with The New York Times that the request to revisit the deal was somewhat spontaneous. “This whole trade thing has exploded,” Mr. Kudlow said. “There’s no deadline. We’ll pull a team together, but we haven’t even done — I mean, it just happened a couple hours ago.”

Mr. Trump’s decision to throw out the Trans-Pacific Partnership and his pledge to tear up the North American Free Trade Agreement were bedrock promises of his populist campaign, which centered heavily on unfair trade practices that he said had robbed American manufacturers and workers.

As he often does, the president started to change gears after hearing complaints from important constituents — in this case, Republican lawmakers who said farmers and other businesses in their states would suffer from his trade approach since they send many of their products abroad.

Then late Thursday, Mr. Trump appeared to shift gears again, saying in a Twitter post at 11:15 p.m. that he would consider re-entering the agreement only if it were “substantially better” than the deal offered to President Barack Obama. “We already have BILATERAL deals with six of the eleven nations in TPP,” he wrote, “and are working to make a deal with the biggest of those nations, Japan, who has hit us hard on trade for years!”

The discussion on the trade deal began at the White House meeting earlier on Thursday, when Senator John Thune, Republican of South Dakota, questioned Mr. Trump about returning to the pact, arguing that the Trans-Pacific Partnership was the best way to put pressure on China.

Mr. Trump, who has put China’s “unfair” trade practices in his cross hairs, turned to Mr. Kudlow and Robert Lighthizer, his trade negotiator, and asked them to look into re-entering the agreement.

Rejoining the pact could be a significant change in fortune for many American industries that stood to benefit from the trade accord and for Republican lawmakers who supported it. The deal, which was negotiated by the Obama administration, was largely intended as a tool to prod China into making the type of economic changes that the United States and others have long wanted. Many economists say the best way to combat a rising China and pressure it to open its market is through multilateral trade deals like the Trans-Pacific Partnership, which create favorable trading terms for participants.

“The idea was to set a framework that eventually China would have to accommodate,” said David Autor, an economist at M.I.T.

Farmers would stand to benefit from new access to markets, especially Japan, if Mr. Trump rejoins the pact. For instance, ranchers in Australia can currently send beef to Japan more cheaply than ranchers in the United States.

Michael Miller, the chairman of U.S. Wheat Associates and a farmer in Washington, said rejoining the deal would allow his industry to compete on a level playing field with competitors in Australia and Canada, which both remained in the accord.

But rejoining it could be a complex task. The remaining countries, like Japan, moved ahead without the United States, and spent months renegotiating a pact before finally agreeing to a sweeping multinational deal this year. Mr. Trump, who has demanded that any such deal benefit the United States, is unlikely to rejoin the Trans-Pacific Partnership without further concessions for what he has criticized as a terrible agreement. That could complicate talks, since Japan maintains that it has already given all the concessions it could, said William A. Reinsch, a trade expert at the Center for Strategic and International Studies.

Yoshihide Suga, Japan’s chief cabinet secretary, on Friday cautioned against any efforts to change the agreement to accommodate Mr. Trump, calling it a “well-balanced pact” that addressed the needs of the 11 nations that signed the deal.

It is also unclear how serious Mr. Trump is about rejoining. In the past, the president has floated policies that appeared to run counter to his earlier positions, like cooperating with Democrats on legislation governing immigration and gun rights, then quickly abandoned them.

“What he tells people in a room to make them happy does not always translate into administration policy,” said Phil Levy, a senior fellow at the Chicago Council on Global Affairs.

In a statement, a deputy White House press secretary, Lindsay Walters, pushed back on the notion that Mr. Trump was reversing his promises.

The president had “kept his promise to end the TPP deal negotiated by the Obama administration because it was unfair to American workers and farmers,” she said. “The president has consistently said he would be open to a substantially better deal.”

But the White House is in somewhat of a box when it comes to prodding China to fall in line with global trade rules. The administration is trying to use tariffs to force Beijing to open its markets, but many of his supporters, including business groups and farmers, fear the fallout from an escalating trade war will be even more damaging. China has responded to Mr. Trump’s threat of tariffs on as much as $150 billion worth of its goods by placing its own tariffs on American pork, and threatening taxes on soybeans, sorghum, corn and beef.

Some advisers, including Mr. Kudlow, have indicated that those tariffs may never go into effect, and that they are mainly a prelude to negotiations with the Chinese, statements that have helped calm volatile stock markets. In a recent note to clients, the ratings agency Fitch said that the most likely outcome to the conflict remained a “negotiated solution” and that it was therefore not changing its primary economic forecast.

Mr. Kudlow, in the interview, said that farmers had “a legitimate concern” but added that it would be “at least two months before final decisions will be made.”

“I’m not here to say we won’t use tariffs — everything’s on the table in these negotiations — but I am here to say we don’t know yet,” he said.

Still, White House officials suggest that little to no progress has yet been made in bridging contentious gaps with the Chinese. Administration officials say that back-channel talks have occurred, but they would not characterize them as official negotiations. The Chinese appear impassable on some of the issues that the White House is most concerned about, including their subsidies to cutting-edge industries like robotics, aerospace and artificial intelligence.

The Trump administration says it has ordered the Agriculture Department to create a program to help farmers should the two nations find themselves in a trade war. Trade advisers say the department could draw on the financial resources of a program known as the Commodity Credit Corporation, which provides up to $30 billion to help shore up American farmers by buying their crops.

“Stay with us while we go through this difficult process,” Mr. Kudlow told farm-state representatives during the meeting, according to a White House transcript. He added, “And at the end, if the worst case has come out as the president said, you will be helped. That’s a promise.”

But such a program would be time-consuming and costly and would come as the budget deficit continues to increase. Farmers say that Mr. Trump’s threats have already hurt them by causing the price of futures contracts to fall. They maintain that the easiest way to help them is to avoid a trade war with China in the first place.

Senator Joni Ernst, Republican of Iowa, described the meeting with the president as “productive” and said that she had urged him to re-engage in discussions with countries in the Trans-Pacific Partnership. “Iowa farmers aren’t looking for another subsidy program; rather they want new and improved market access,” she said.

“The best thing the United States can do to push back against Chinese cheating now is to lead the other 11 Pacific nations that believe in free trade and the rule of law,” Senator Ben Sasse, Republican of Nebraska, who attended the meeting, said in a statement. “It is good news that today the president directed Larry Kudlow and Ambassador Lighthizer to negotiate U.S. entry into TPP.”

A version of this article appears in print on , on Page A1 of the New York edition with the headline: Trump Weighs Rejoining Accord With Pacific Rim in About-Face. Order Reprints | Today’s Paper | Subscribe