Stocks closed sharply lower Friday, with the market logging its worst May since 2010, after President Donald Trump unexpectedly announced plans to impose tariffs on imports from Mexico in an attempt to pressure the country to stem the flow of migrants across the U.S. border.

Meanwhile, reports said China may be readying fresh retaliatory moves against the U.S. in that trade dispute, while data showed a contraction in Chinese manufacturing activity this month.

The Dow Jones Industrial Average DJIA, +0.19% dropped 354.84 points, or 1.4%, to 24,815.04. The S&P 500 index SPX, +0.29% fell 36.80 points, or 1.3%, to 2,752.06 and the Nasdaq Composite COMP, +0.36% dropped 114.57 points, or 1.5%, to 7,453.15.

May, which in recent years has been a good month for stocks, has been dismal this year with the Dow falling 6.7% while the large-cap index lost 6.6% and the Nasdaq declined 7.9%. For the week, the blue-chip gauge shed 3% for its sixth straight week of losses, the longest weekly retreat since June 2011. The S&P 500 was off 2.6% and the Nasdaq slid 2.4% for the week.

Read:Stock market on track for ‘key’ monthly reversal that ‘presages deeper declines,’ technician says

What drove the market?

Late Thursday, just as Asian markets began trading, Trump announced in a tweet that the U.S. would impose a 5% tariff on all goods from Mexico until that country stops the flow of illegal immigrants into the country. He said the tariffs will rise to 10% on July 1 if the crisis persists, and by another 5% for every successive month, up to 25% by Oct. 1.

“Tariffs will permanently remain at the 25% level unless and until Mexico substantially stops the illegal inflow of aliens coming through its territory,” Trump said.

The threat comes as the White House triggered the process for submitting a bill to Congress that would implement the new the U.S.-Mexico-Canada Agreement, the successor to the North American Free Trade Agreement.

Stocks were also battered after a tweet from Hu Xijin, the widely followed editor of the Global Times, indicated that China will hit back hard at the U.S. “Based on what I know, China will take major retaliative measures against the U.S. placing Huawei and other Chinese companies on Entity List. This move indicates Beijing won’t wait passively and more countermeasures will follow,” the editor tweeted. Global Times is a Chinese state-owned tabloid that is watched for clues to government policy stances.

Beijing reportedly has a plan ready to go to restrict exports of rare earth materials to the U.S. if they feel it is necessary, according to Bloomberg. Those measures would be concentrated on heavy rare earths, which are used in autos and lots of consumer products and particularly needed by the U.S.

See:Is threat of withholding rare-earth metals a key weapon in China’s trade war with U.S.?

Investors were also digesting negative economic news out of China, as manufacturing activity contracted in May, weighed by weaker export orders amid escalating trade tensions with the U.S.

In the U.S., data showed April personal incomes rose 0.5%, while consumer spending rose 0.3%. The core personal-consumption expenditure, or PCE, index, the Federal Reserve’s preferred inflation measure, rose 0.2%, in line with forecasts.

The University of Michigan’s final consumer sentiment index reading for May came in at 100 versus an initial 102.4, but remained up from 97.2 in April.

What were analysts saying?

“The escalating trade tensions are a challenge. At the moment it is a challenge for market sentiment. It is not yet a challenge for the economic data,” said John Bellows, a portfolio manager at Western Asset Management, in a note. “The models we have looked at suggest the economic impacts could be manageable, and the effects will most likely be transitory. The conflicts could also get resolved. But, if sentiment continues to deteriorate then that itself can become a more serious issue.”

The worst-case scenario is one in which foreign governments, namely China and Mexico, “simply wait Trump out given we’re 19 months from an election,” wrote Tom Essaye, founder of Sevens Report Research, in a report.

“In that outcome, there is no China trade deal and tariffs (Chinese and Mexican) act as an anchor on global growth and market sentiment for 18 months, increasing the chances of recession,” he said.

What stocks were in focus?

Shares of auto makers with substantial production exposure to Mexico were under heavy pressure. Shares of General Motors Co. GM, -0.78% fell 4.3%, while Ford Motor Co. shares F, +0.30% declined 2.3%.

Japanese auto makers tumbled and French and German auto makers also took a beating.

Shares of Uber Technologies Inc. UBER, -0.59% rose 1.5% after the ride-hailing company late Thursday reported a first-quarter loss of $1.01 billion. Investors are cheering assurances from executives that a price war with rival Lyft Inc. LYFT, -0.74% was settling down.

Red Robin Gourmet Burgers Inc. RRGB, -0.53% shares sank 17% after the restaurant chain posted weak quarterly results and a decline in comparable restaurant revenue.

Shares of Big Lots Inc. BIG, +3.13% jumped 6.1% after the retailer reported first-quarter earnings that topped Wall Street expectations.

How were other markets trading?

Stocks in Asia put in a mixed performance, with the Japan’s Nikkei 225 NIK, +0.55% falling 1.6% as the yen climbed and weighed on exporters. China’s Shanghai Composite Index SHCOMP, -0.24% fell 0.2%, while Europe indexes mostly closed lower.

The Mexican peso USDMXN, -0.16% fell sharply, with that currency recently down over 2% against the dollar, while the Japanese yen USDJPY, -0.00% soared on haven-related buying.

Rattled investors also moved into perceived haven assets such as bonds, with the yield on the 10-year note TMUBMUSD10Y, 0.676% dropping 7.4 basis points to 2.151%, while the 2-year note yield TMUBMUSD02Y, 0.140% dipped below 2% for the first time since early 2018.

Oil prices US:CLN19 tumbled, notching their worst monthly decline since November, gold US:GCQ19 rallied to its highest settlement in more than 7 weeks, and the U.S. dollar DXY, -0.00% retreated against its peers.

—Barbara Kollmeyer contributed to this article