Optimism about a deal earlier in the week darkened after fierce opposition from the White House to rolling back existing tariffs surfaced on Thursday and after U.S. President Donald Trump reinforced that sentiment on Friday.

Trump told reporters he has not agreed to the rollback of tariffs sought by China and that Beijing wanted to make a deal more than he did.

But by the close of Wall Street, optimism returned to the market as investors bet the White House needs a deal and it is in the interests of China, too. All three major U.S. indexes eked out record closing highs.

"The feeling now is that before the end of the year we're going to see some type of deal," even if it is partial, said

Tim Ghriskey, chief investment strategist at Inverness Counsel in New York, said.

MSCI's gauge of stocks across the globe pared losses to close little changed, down 0.03% on the day and just 1.3% from then all-time high set in January 2018.

The dollar rose to a three-week high, lifted by safe-haven bids, as risk appetite for higher-yielding currencies was curtailed by the uncertainty over the tariff rollback, a major component of a preliminary U.S.-China trade deal.

Optimism around a deal has run into skepticism about the strength of the economy and corporate results, which is driving fear of more weakness ahead, said Christopher Smart, chief global strategist at Barings.

"It's very difficult of course to forecast what this administration will or will not agree to, but it's going to be hard to keep the peace going into an election year," Smart said. "People are still pretty pessimistic."

The pan-European STOXX 600 index closed down 0.28%, snapping a five-day winning streak, while Germany's trade-sensitive DAX index fell 0.46%.

The record closing high by the S&P 500 was the fourth in six sessions as U.S. stocks rallied on hopes of a trade deal.

The Dow Jones Industrial Average rose 6.44 points, or 0.02%, to 27,681.24. The S&P 500 gained 7.9 points, or 0.26%, to 3,093.08 and the Nasdaq Composite added 40.80 points, or 0.48%, to 8,475.31.

Earlier in Asia, shares retreated from six-month highs.

Investor sentiment is likely to continue to support risk assets as efforts are made to reach a trade deal, said Brian Daingerfield, head of G10 FX strategy at Natwest Markets in Stamford, Connecticut. "The fact that there is some discussion of moving existing tariffs leans more positive."

The dollar index rose 0.23%, with the euro down 0.27% to $1.1019. The Japanese yen strengthened 0.08% versus the greenback at 109.22 per dollar.

U.S. Treasury yields traded mostly below three-month highs while Germany's 10-year bond yield slid from five-month highs.

The yield on benchmark 10-year German bunds was one basis point lower at -0.26%.

Benchmark 10-year U.S. Treasury notes fell 5/32 in price to push their yield up to 1.9399%.

Gold extended losses to a three-month low and was on track for the biggest weekly decline in almost three years. U.S. gold futures settled down 0.2% at $1,462.90.

Oil prices pared losses after earlier falling more than 1% following Trump's comments.

Benchmark Brent crude fell 80 cents to $61.49 a barrel while West Texas Intermediate (WTI) crude rose 9 cents to settle at $57.24 a barrel.

"Given the volatility around the U.S.-China trade saga, it's hard to be short over the weekend," said John Kilduff, a partner at Again Capital LLC. "The turn of a phrase could restore the very hopes that were dashed just last night over a deal being struck."

By Herbert Lash