U.S. stocks pulled well off the day’s lows Thursday but the S&P 500 and the Nasdaq finished lower for a fourth session as trade tensions ramped up after U.S. President Donald Trump threatened tariff retaliation on China, which he claims “broke the deal”.

However, some of the fears were assuaged after Trump disclosed that he’s received a missive from Chinese President Xi Jinping just hours before U.S. and Chinese officials were set to resume trade talks in Washington.

The Dow Jones Industrial Average DJIA, +1.12% fell 138.97 points, or 0.5%, to end at 25,828.36 after falling by as much as 450 points earlier. The S&P 500 index SPX, +1.25% dropped 8.70 points, or 0.3%, to 2,870.72 and the Nasdaq Composite Index COMP, +1.53% lost 32.73 points, or 0.4%, to 7,910.59.

What drove the market?

Anxiety over the prospect of a deepening trade dispute between the U.S. and China has weighed on stock markets all week, after Trump voiced frustration over the pace of talks in a Sunday tweet. Those fears were compounded Wednesday evening when the president accused the Chinese of negotiating in bad faith and reneging on commitments made in previous rounds of negotiation.

See:How U.S.-China trade uncertainty could trigger a stock-market buy signal

In response, the White House has threatened to raise tariffs on $200 billion in annual Chinese exports to the U.S. to 25% from the current 10% at 12:01 Eastern Time Friday.

The rift has come amid accusations by the U.S. that China has been trying to back out of already agreed measures, prompting Trump to slap higher tariffs on the country. China has taken a tougher stance on negotiations because officials believed the U.S. was ready to compromise, based on recent actions and comments by Trump, The Wall Street Journal reported.

Read:‘China has chosen to retreat’—the U.S. view as negotiations reach critical juncture

But Trump’s disclosure that he received a “beautiful letter” from Xi and his suggestion that there was scope for a deal helped to ease some of the pressure on the market as Beijing’s top trade envoys, including Vice Premier Liu He, arrived in Washington to resume negotiations.

Read:With Trump threatening to tighten the trade screws, here’s a look at what tariffs have done so far

What were analysts saying?

Before Trump’s Sunday tweet, when greater tariffs were threatened, “our sources in Washington were anticipating a ‘weak’ deal with few genuine Chinese concessions,” wrote James Sweeney, chief economist for Credit Suisse, in a note to clients.

“Moreover, no large institutional investors were predicting — at least publicly — an imminent tariff increase,” he added. “While the tweet led to a selloff in China’s equity markets on Monday, the relatively muted market reaction in Europe and the U.S.A. suggests that a large tariff increase remains a tail risk rather than a base-case scenario.”

“Trade negotiating tactics are clearly being used by both the U.S. and China,” wrote Edward Moya, senior market analyst at Oanda, in a research note. “Give-and-take was to be expected by both sides as we near an ultimate conclusion to a trade deal. Recent obstacles have seen the risk of a total collapse grow which means we could be finally nearing a deal.”

“While the base case remains for a deal to be reached, the timing is uncertain, but likely to occur by early June at the latest.” he added. “If we see a disastrous outcome this week, we could see a 10% correction with U.S. equities. A framework agreement is likely to see stocks attempt another run at making fresh record highs.”

Read:Here are this week’s biggest stock-market losers as Trump’s trade war on China continues

What speakers and data were in focus?

Federal Reserve Chairman Jerome Powell discussed the “crucial” problems of stagnant middle-class incomes and economic mobility at the Fed’s community development research conference Thursday morning.

The number of people who applied for jobless benefits in the week ended May 4 fell slightly to 228,000, the Labor Department said Thursday, above the 218,000 expected by economists polled by MarketWatch.

U.S. wholesale prices rose 0.2% in April, below the 0.3% increase expected by economists, per a MarketWatch poll. The annual increase in producer prices remained flat at 2.2%.

The U.S. trade deficit widened in March versus February, but the bilateral deficit with China fell to the lowest level in three years, the Commerce Department said Thursday.

Wholesale inventories in the U.S. fell 0.1% in March, the Commerce Department said Thursday, versus consensus expectations of a 0.3% rise, according to FactSet.

Which stocks were in focus?

Uber Technologies Inc. UBER, +0.87% is expected to price its initial public offering later Thursday at “the midpoint or below” its $44 to $50 per share target, The Wall Street reported, (paywall), with its public debut on the New York Stock Exchange to occur Friday.

Shares of Etsy Inc. ETSY, +0.27% sank 11% after the online marketplacereported first-quarter earnings Wednesday evening, with the company reporting profit and sales that grew more slowly that analysts had predicted.

Shares of Tapestry Inc. TPR, +0.24% rallied 8.5% after the parent company of Coach and Kate Spade brands reported fiscal third-quarter earnings that beat expectations and authorized a $1 billion stock repurchase program.

Shares of Perrigo Company PLC PRGO, +0.28% jumped 7% after the company announced a “self-care transformation plan” and long-term growth targets during an investor day held Thursday.

Roku Inc. ROKU, -3.60% stock popped 28% following a Wednesday-evening earnings report that showed the streaming platform company beating earnings expectations for the first quarter, while it forecast second-quarter revenue that also beat estimates.

Shares of AMC Entertainment Holdings Inc. AMC, -1.10% skidded 7% after the cinema chain operator posted a wider-than-expected loss for the first quarter.

Shares of e.l.f Beauty Inc. ELF, -0.34% slumped 7.3% after the company reported a surprise loss on for the three-month period ended in March on Wednesday evening.

Shares of Arena Pharmaceuticals Inc. ARNA, +0.94% reversed direction to rise 3.5% after the drug company reported first-quarter earnings that disappointed Wall Street.

Fox Corp. FOXA, +1.73% stock advanced 2.9% after the company reported its first quarterly earnings as a stand-alone company, beating analyst forecasts for earnings and sales. Fox was spun off from 21st Century Fox earlier this year, and began trading as its own entity in March.

How were other markets trading?

In Asia, trade tensions rattled markets, with the Hang Seng Index HSI, -1.81% down 2.4%, and the Shanghai Composite Index SHCOMP, -1.72% off 1.5%. The Stoxx Europe 600 SXXP, -1.02% fell 1.7%.

Gold US:GCM9 settled higher, the U.S. dollar fell against the Japanese yen USDJPY, +0.02% , perceived by investors as a haven investment, and crude oil prices US:CLM9 the declined.

—Barbara Kollmeyer contributed to this report