Stocks closed little changed as investors wrapped up a quarter that featured strong gains.

For the quarter, the S&P 500 rose 7.2 percent, its best quarterly gain since the fourth quarter of 2013. The Nasdaq Composite also notched a 7.1 percent quarterly gain, its best since first quarter 2017. The Dow Jones Industrial Average outperformed in the third quarter, rising 9.3 percent.

Health care was the best-performing sector of the third quarter, surging 14.1 percent, its best quarterly gain since the first quarter of 2013. Industrials and tech, meanwhile, rose 9.7 percent and 8.5 percent.

Equities rose broadly as investors cheered stronger-than-expected quarterly results. Calendar second-quarter earnings for the S&P 500 rose 25 percent on a year-over-year basis, with 77.6 percent of companies topping analyst expectations, FactSet data show.

Heading into the fourth quarter, investors will face uncertainty amid a hotly anticipated mid-term election in November. Democrats are expected to gain a majority in the House as well as increase their seat count in the Senate. This could delay, or even thwart, the Trump administration's economic agenda.

Trade concerns, which capped gains on Friday, will also linger heading into year-end. The fell marginally Friday to 2,913.98 while the Nasdaq eked out a small gain to close at 8,046.35. The Dow, meanwhile, climbed 18.38 points to 26,458.31 as Intel and Boeing outperformed.

The U.S. and Canada have not yet come to an agreement on their trade relationship with a Sept. 30 deadline rapidly approaching.

The two countries are trying to come to terms so that Canada can join a trade deal struck between the U.S. and Mexico. The new deal would replace the current North American Free Trade Agreement (NAFTA), which has been heavily criticized by President Donald Trump.

U.S. Trade Representative Robert Lighthizer said Tuesday the U.S. was ready to move ahead on a new NAFTA deal without Canada.

Trump, meanwhile, said Wednesday he was "very unhappy" with Canada's negotiation tactics, noting: "We don't like their representative [Chrystia Freeland] very much."