President Donald Trump, incensed by a surge of illegal immigrants across the southern border, vowed on Thursday to impose a tariff on all goods coming from Mexico, starting at 5% and ratcheting higher until the flow of people ceases. Trump’s move dramatically ramped up his battle to control a tide of immigrants that has swelled despite his efforts to build a border wall and halt the thousands crossing from Central America through Mexico to the U.S. border.

The president’s decision, abruptly announced on Twitter and in a subsequent statement, was a direct challenge to Mexican President Andres Manuel Lopez Obrador and appeared to take the Mexican government by surprise.

It raised the risk of deteriorating economic relations between two neighbors heavily dependent on the cross-border flow of goods. It also opened up a new front on trade as the Trump administration struggles to conclude a trade deal with China.

Higher tariffs will start at 5% on June 10 and increase monthly until reaching 25% on Oct. 1, unless Mexico takes immediate action, he said.

“If the illegal migration crisis is alleviated through effective actions taken by Mexico, to be determined in our sole discretion and judgment, the tariffs will be removed,” Trump said.

The announcement rattled investors who feared that worsening trade frictions could hurt the global economy. The Mexican peso, U.S. stock index futures and Asian stock markets tumbled on the news, including the shares of Japanese automakers who ship cars from Mexico to the United States.

“We’re in a good moment building a good relationship (with the United States) and this comes like a cold shower,” said Mexico’s deputy foreign minister for North America, Jesus Seade.

U.S. officials said 80,000 people are being held in custody with an average of 4,500 arriving daily, overwhelming the ability of border patrol officials to handle them.

A senior White House official said Trump was particularly concerned that U.S. border agents apprehended a group of 1,036 migrants as they illegally crossed the border from Mexico on Wednesday. Officials said it was the largest single group since October.

A source close to Trump said there had been an internal debate inside the White House over whether to go forward with the new policy, with immigration hawks fighting for it and others urging a more diplomatic approach. Trump sided with the hawks.

“The last thing he wants is to look weak,” said the source, who spoke on condition of anonymity.

Trump’s directive also spelled the potential for chaos for his efforts to get the U.S. Congress to approve his USMCA trade deal, which he sees as a replacement to the North American Free Trade Agreement between the United States, Mexico and Canada.

Doug Ducey, the governor of Arizona, which shares a 370-mile (595-km) border with Mexico, said on Twitter that he spoke to the White House and it was time for Congress to act on border security and the United States-Mexico-Canada Agreement.

“Everyone knows I am opposed to tariffs and deeply value Arizona’s relationship with Mexico. I prioritize national security and a solution to our humanitarian crisis at the border above commerce,” he said in a Tweet.

Mexico’s Seade said it would be disastrous if Trump goes through with his threat to impose the tariffs. Calling Trump’s move “extreme,” Seade said a normal response would be for Mexico to “mirror” the U.S. tariffs but that would lead to a trade war.

Trump said he was acting under the powers granted to him by the International Emergency Economic Powers Act. He campaigned for election in 2016 on a vow to crack down on illegal immigration.

“Mexico’s passive cooperation in allowing this mass incursion constitutes an emergency and extraordinary threat to the national security and economy of the United States,” Trump said in the statement.

“Mexico has very strong immigration laws and could easily halt the illegal flow of migrants, including by returning them to their home countries,” he said.

WHITE HOUSE WANTS ACTION ‘TONIGHT’

White House acting chief of staff Mick Mulvaney, asked in a conference call with reporters which products from Mexico could be affected by the tariffs, said: “All of them.”

Mulvaney added, “This is an urgent problem. We are interested in seeing the Mexican government act tonight, tomorrow.”

“The threat of U.S. tariffs on Mexico to take effect inside two weeks is a sharp blow to investor sentiment,” said Sean Callow, a senior currency analyst at Westpac.

“Mexico is the U.S.’s largest trading partner and a flare-up in trade tensions was definitely not on the market radar.”

The benchmark S&P 500 e-mini futures dropped 0.82% to the lowest the contract has traded since early March. Investors scooped up safe assets, driving the yield on the 10-year U.S. Treasury note to 2.18%, the lowest since September 2017. The dollar surged against the Mexican peso.

U.S. officials say the immigration system is being overwhelmed by thousands of migrants, many of whom turn themselves into border officials to claim asylum in the United States. Border facilities are straining to handle large numbers of people and many children.

At least six migrant children have died in U.S. custody or shortly after being released. Apprehensions of migrants on the southwest border hit another record high last month, with 98,977 people arrested.