President Trump on Thursday said he would impose a 5 percent tariff on all goods entering from Mexico unless it stopped the flow of illegal immigration to the United States, a dramatic escalation of his border threats that could have sweeping implications for both economies.

The White House plans to begin levying the import penalties on June 10 and ratchet the penalties higher if the migrant flow isn’t halted. Trump said he would remove the tariffs only if all illegal migration across the border ceased, though other White House officials said they would be looking only for Mexico to take major action.

After the 5 percent tariffs are imposed on June 10, the White House said it would increase the penalties to 10 percent on July 1 and then an additional 5 percent on the first day of each month for three months. The tariffs would stay at 25 percent “until Mexico substantially stops the illegal inflow of aliens coming through its territory,” a statement by the president said.

The economic consequences of Trump’s new plan could be swift and severe. Tariffs are paid by companies that import products, so U.S. firms would pay the import penalties and then likely pass some costs along to consumers. Mexico exported $346.5 billion in goods to the United States last year, from vehicles to fruits and vegetables. And many manufactured items cross the border several times as they are being assembled.

White House officials did not immediately explain how driving up the cost of Mexican goods might stem the flow of migrants. If the tariffs damaged the Mexican economy, more of its citizens would try to cross the border to find work in the United States, experts said.

“Mexico is our friend and neighbor, a partner in trade and security,” said Glenn Hamer, chief executive of the Arizona Chamber of Commerce and Industry. “The president’s announcement is baffling and, if carried out, will be terribly damaging.”

Mexico vowed a response that could pitch the Trump administration into a full-scale trade war with one of its largest trading partners. This comes just days after the White House and China imposed stiff penalties on each other’s exports.

At a news conference, Mexico’s deputy foreign minister for North America, Jesús Seade, said the threatened tariffs would be “disastrous” and added that Mexico would respond “strongly.”

In a letter sent Thursday evening, Mexican President Andrés Manuel López Obrador addressed Trump in harsh terms, a marked change from the diplomatic posture he has tried to adopt since being elected last July. “President Trump, social problems can’t be resolved through taxes or coercive measures,” López Obrador wrote.

He said he would send his foreign minister to Washington on Friday “to arrive at an agreement that benefits both nations.”

But even as López Obrador suggested that there was a diplomatic solution, he unloaded on Trump for his administration’s immigration policy.

“How did a country of fraternity for all the migrants in the world become, from night to dawn, a ghetto, a closed space,” where migrants are stigmatized and mistreated, López Obrador wrote. He went on: “The statue of liberty is not an empty symbol.”

Trump has often tried to use tariffs and other import penalties as a way to pressure countries into changing behavior, but he has not yet done it on such a scale. In addition, he wrongly has said the cost of tariffs are shouldered by the countries that he targets.

Even some White House officials were caught off guard by the announcement, though planning within the West Wing escalated on Thursday afternoon. Vice President Pence was in Canada on Thursday, meeting with Canadian Prime Minister Justin Trudeau about ratifying an updated version of the North American Free Trade Agreement with Mexico, but it’s unclear if Trump’s newest tariff threat could upend those discussions.

White House officials believe Trump has powers under a 1977 law to impose tariffs on all imports from certain countries if he cites a “national emergency.” And several months ago, Trump declared a national emergency along the Mexico border because of a surge in migrants crossing into the United States.

But the 1977 law has never been used to impose tariffs in this way before, and Trump’s new actions could face legal challenges because of the scope of companies that would be impacted.

The new tariff threat combines two of Trump’s favorite issues — immigration and trade — and comes as he has struggled to score victories on either one.

A central element of Trump’s campaign was his assertion that the United States was being “invaded” by people across the Mexico border, a sentiment that resonated with many supporters. He has tried to rework trade rules and build a wall to stop the flow of migrants, but so far his efforts have failed to stem the surge of people crossing the border. Crossings at the U.S.-Mexico border, driven by Central American migrants seeking asylum, have peaked to their highest level in more than a decade.

One senior White House official, who spoke on the condition of anonymity to discuss internal deliberations, said there is broad support across the administration to push Mexico further by using tariffs to force action. Other aides, however, tried to talk Trump out of the idea, arguing that the threat would scare global markets and undermine passage of the United States-Mexico-Canada Agreement, or USMCA, which was just sent to Congress on Thursday by the White House. The trade deal aims to curb the type of tariffs Trump is now threatening to impose on Mexico.

“Trade policy and border security are separate issues,” Sen. Charles E. Grassley (R-Iowa), chairman of the Senate Finance Committee, said in a statement. “This is a misuse of presidential tariff authority and counter to congressional intent. Following through on this threat would seriously jeopardize passage of USMCA, a central campaign pledge of President Trump’s and what could be a big victory for the country.”

The president teased his plans on Thursday morning, telling reporters outside the White House that he was preparing a “big-league statement” about the border surge, without going into detail.

“We are going to do something very dramatic on the border because people are coming into our country,” Trump said.

On Wednesday, more than 1,000 Central Americans crossed into the El Paso area to surrender to U.S. authorities, the largest group of migrants that U.S. border agents have taken into custody at a single time. Trump tweeted a video of the apprehension late Thursday, declaring that “Democrats need to stand by our incredible Border Patrol and finally fix the loopholes at our Border!”

Deportations by Mexican authorities have increased threefold compared with the same period last year, according to the latest statistics, but the vast majority of Central American migrants appear to be successful at evading arrest en route to the U.S. border.

López Obrador campaigned last year on a promise to decriminalize migration and told audiences it was not Mexico’s job to assist the United States with the “dirty work” of deportations.

Trump has backed down on previous threats aimed at Mexico. He abandoned his oft-repeated campaign promise to make that country pay for a border wall. Trump is now using the powers of his national emergency to redirect U.S. taxpayer funds for the construction of replacement fences and barriers along the border.

In late March, Trump said he would immediately shut down the entire border if the Mexican government didn’t take more steps to prevent the flow of migrants, only to announce a week later that he would delay any action for a year. White House officials had spent days frantically trying to design how such a shutdown would be implemented.

The draft trade agreement sent to Congress on Thursday would, if ratified, replace the 1994 NAFTA deal. The draft allows Trump to send a final agreement in 30 days, a timeline intended to pressure House Speaker Nancy Pelosi (D-Calif.), who along with other Democrats wants changes to the agreement before any vote.

The top imports from Mexico include vehicles, electrical machinery, machinery, mineral ­fuels, and optical and medical instruments, according to the Office of the U.S. Trade Representative. The United States also imports a large amount of agricultural products from Mexico.

A March 2019 report from the Congressional Research Service said that the 1977 International Emergency Economic Powers Act had never been used before “to place tariffs on imported products from a specific country” but that it could be interpreted as giving the White House that power.

Along the Mexico border, U.S. agents have detained more than 100,000 migrants for each of the past two months, and the numbers in May are expected to be the highest yet.

In recent months, smuggling organizations have been moving large numbers of migrants from southern Mexico using “express buses” that reach the U.S. border in a matter of days. The buses make few stops and have lowered the costs for migration, making the journey faster, easier and cheaper for would-be customers.

U.S. officials say corrupt Mexican officials are allowing the ­buses to pass through highway checkpoints and in other cases facilitating their travel to the border by providing security escorts.

Mexican officials have said they’re doing everything they can to regulate the migration surge, and they provide police escorts in some cases to prevent criminal organizations from kidnapping and extorting families traveling with small children.

A Mexican official, speaking on the condition of anonymity to discuss sensitive diplomatic negotiations, said trade-related talks with U.S. officials have remained “positive,” and noted that López Obrador was also preparing to send the trade deal to lawmakers for approval. The official declined to say whether the White House has conditioned the deal on a migration crackdown by Mexican authorities.

Kevin Sieff in Mexico City and Colby Itkowitz in Washington contributed to this report.