U.S. stocks closed mostly higher, but off the best levels Monday, after the U.S. and Canada reached a deal to revise the North American Free Trade Agreement. The news helped to alleviate some of the concerns surrounding trade that have periodically weighed on the market over the past several months.

The Dow Jones Industrial Average DJIA, +0.44% gained 192.90 points, or 0.7%, to 26,651.21 and the S&P 500 SPX, +0.10% advanced 10.61 points, or 0.4%, to 2,924.59. The Nasdaq Composite Index COMP, -0.18% , meanwhile, reversed direction to fall 9.05 points, or 0.1%, to 8,037.30.

Monday marked the first day of October, as well as the start of the fourth quarter. The S&P is coming off its best such three-month stretch since 2013, climbing more than 7%, while the Dow advanced 9%. The Nasdaq gained more than 7% during the period, its ninth straight quarterly gain.

Read: A 6-month win streak for the stock market may mean that the rally is just getting started

What drove trading?

The fourth quarter’s opening session kicked off with an unexpected breakthrough in U.S.- Canada trade negotiations. In a news conference, President Donald Trump called the deal “truly historic.” Among other changes, the deal for the first time sets rules for categories of financial-services and digital businesses that have emerged since the bloc was created.

The development came just four days after U.S. Trade Representative Robert Lighthizer had told Congress that chances were slim that a Canada deal would be reached in time to meet a U.S.-imposed deadline.

Read: If the trade situation worsens, look for stocks with this characteristic, Goldman Sachs says

In the latest economic data, a reading on U.S. manufacturing from Markit came in at 55.6, compared with a previous reading of 54.7, while a reading on manufacturing from the Institute for Supply Management came in at 59.8, slightly below expectations.

Investors also kept an eye on Europe after Italy’s antiestablishment government significantly widened its budget-deficit target for next year, potentially setting the country on a collision course with the European Union.

In the U.K., the Conservatives’ annual party conference was getting under way with Prime Minister Theresa May facing pressure over her proposal for future U.K.-EU relations, known as the Chequers plan, which has already been rejected by EU leaders.

See:Italy’s budget turmoil: Here’s what it will take to rattle global markets

What were analysts saying?

“Although the trade outlook with China remains uncertain, overall trade uncertainty has been receding for months, helping propel stocks to record highs,” said Alec Young, managing director of global markets research at FTSE Russell. “And even when it comes to China many investors are betting there’s room for a market friendly compromise.”

He added: “International stocks have even more to gain from trade breakthroughs than their U.S. counterparts because they have been held back too far by trade worries due to their economies’ increased sensitivity to trade.”

What stocks were in focus?

Shares of Tesla Inc. TSLA, -4.25% jumped 17% after Chairman and Chief Executive Elon Musk settled a Securities and Exchange fraud probe. The settlement will force him to step down as chairman and cost him and the company a combined $40 million in fines. He also reportedly told employees in a weekend email that the electric-car maker is on the verge of making a profit.

Shares of General Electric Co. GE, +1.12% surged 7.1% after the troubled industrial conglomerate said its chief executive officer, John Flannery, was being replaced after a little over a year in the role. GE named a new CEO, announced a noncash goodwill impairment charge of about $23 billion, and said it would fall short of its 2018 profit outlook. The stock had dropped more than 25% thus far this year.

Pfizer Inc. PFE, -0.34% said that Chief Executive Officer Ian Read plans to step aside at the end of the year, and will hand the reins to deputy Albert Bourla. Shares of the Dow component were up 0.5%.

Cal-Maine Foods Inc. CALM, -0.05% tumbled 6.8% after the company reported first-quarter earnings and sales that missed expectations. It also cut its quarterly dividend.

Viking Therapeutics Inc. shares VKTX, +0.15% slid 7%. The company reported positive results in a midstage trial of a treatment for broken hips.

Shares of Facebook Inc. FB, +0.06% fell 1.2%. The social-media giant had seen its shares slump on Friday, too, after an announcement that hackers had compromised the accounts of more than 50 million users. A European Union privacy watchdog could fine the company as much as $1.63 billion for the data breach.

Related:Facebook picks new top executive for Instagram unit

Shares of Akorn Inc. US:AKRX plummeted 59% after a Delaware court ruled in favor of Fresenius SE & Co. FRE, +1.49% , which has sought to end a $4.3 billion merger with Akorn.

How did other markets trading?

Chinese and Hong Kong markets were closed for holidays, while the Nikkei 225 index NIK, -0.05% rose 0.5%. European stocks SXXP, +1.25% were higher after a sluggish start.

The Canadian dollar USDCAD, +0.24% powered ahead on the trade-deal news and the Mexican peso also climbed against the dollar USDMXN, +1.30% .

—Barbara Kollmeyer contributed to this article.