NEW YORK (Reuters) - U.S. stocks ended more than 1% higher on Friday though well off the day’s highs after the announcement of a partial trade deal between the United States and China.

Indexes cut their gains late in the session as the deal was announced amid worries over the possibility of further flare-ups before the agreement is finalized, strategists said.

President Donald Trump, speaking to reporters after talks with Chinese Vice Premier Liu He, said the United States and China had come to a substantial phase-1 trade deal, reaching agreement on intellectual property, financial services and big agricultural purchases.

The preliminary, partial deal was the biggest step toward resolving a 15-month tariff war between the world’s two largest economies.

The market had risen in recent days due to optimism for an agreement and the S&P 500 .SPX was up as much as about 1.9% earlier in the session.

“The main reason the market rallied the past couple of days was hope that there would be an agreement, even a small agreement, and that this trade war would be done for the foreseeable future,” said Michael O’Rourke, chief market strategist at JonesTrading in Greenwich, Connecticut.

“It looks like while there is an agreement, this is still going to ... drag out and be an issue.”

Top-level discussions between the two countries concluded their second day on Friday.

Cyclicals were among the day's best-performing groups, with the S&P industrial index .SPLRCI up about 2% ahead of the third-quarter earnings season, which is set to begin next week.

FILE PHOTO: Traders work on the floor at the New York Stock Exchange (NYSE) in New York, U.S., October 9, 2019. REUTERS/Brendan McDermid

The Dow Jones Industrial Average .DJI rose 319.92 points, or 1.21%, to 26,816.59, the S&P 500 .SPX gained 32.14 points, or 1.09%, to 2,970.27 and the Nasdaq Composite .IXIC added 106.27 points, or 1.34%, to 8,057.04.

Indexes also gained for the week, with the Dow and Nasdaq up 0.9% each and the S&P 500 up 0.6%.

The timing of the trade news had a lot to do with the late-day volatility, said Michael James, managing director of equity trading at Wedbush Securities in Los Angeles.

“There were 15 minutes to go in the trading day on a Friday ... after the Dow had risen 700 points in the last two days,” he said. “Anything that was less than a comprehensive agreement was likely to see some degree of market sell off.”

Analysts expect S&P 500 earnings to have declined 3.2% year-on-year in the third quarter, which would mark the first fall since 2016, according to IBES data from Refinitiv.

Bets for another interest rate cut by the Federal Reserve fell after data showed a rise in consumer sentiment for the month of October.

Apple's stock AAPL.O rose 2.7% as Wedbush raised its price target, citing confidence in the company's new video streaming service.

The S&P industrial index was boosted by a 17.2% jump in shares of Fastenal Co FAST.O after the industrial distributor beat quarterly profit expectations.

Advancing issues outnumbered declining ones on the NYSE by a 3.14-to-1 ratio; on Nasdaq, a 3.08-to-1 ratio favored advancers.

The S&P 500 posted 27 new 52-week highs and no new lows; the Nasdaq Composite recorded 44 new highs and 60 new lows.

Volume on U.S. exchanges was 7.59 billion shares, compared to the roughly 7 billion average for the full session over the last 20 trading days.