Stocks closed slightly higher on Tuesday, boosted by an improved outlook on global trade after the U.S. and Mexico struck a deal.
The rose marginally to 2,897.52, but posted a record close and briefly broke above 2,900 for the first time ever. The Nasdaq Composite also hit a record high, climbing 0.1 percent to 8,030.04 as Apple rose 0.8 percent. The Dow Jones Industrial Average advanced 14.38 points to 26,064.02.
The market's slight gains on Tuesday came a day after a rally propelled the S&P 500 and Nasdaq to record highs.
Nicholas Colas, co-founder of DataTrek Research, said in a note the recent breakout is "a function of a baseline assumption (further corporate earnings growth and low rates) and a fresh input (a US Mexico trade deal means other trade/tariff negotiations are also likely)."
"Trade has been the biggest overhang on US stocks, so the latter point has some runway to shove large caps even higher in the near term," he said.
The U.S. and Mexico announced Monday they came to an agreement that would replace NAFTA, an accord that currently includes both countries and Canada.
President Donald Trump said this pact would be named "The United States-Mexico Trade Agreement"; and will last for 16 years, with it being placed under review every six years. Negotiations with Canada have not started, but Trump indicated he is open to striking a deal with the neighboring country.
Treasury Secretary Steven Mnuchin told CNBC's "Squawk Box" on Tuesday he is hopeful a deal with Canada will get done, but added he is prepared to "move forward with Mexico." Mnuchin also said: "This is a great deal for American workers. If you remember one thing, this deal is about more trade for U.S. companies and goods and services, and that's what we're focused on."
Trump has repeatedly railed against NAFTA, calling it the worst trade deal ever. On Monday, he said: "The name NAFTA has a bad connotation because the United States was hurt very badly by NAFTA."
Trade spats between the States and other major economies have put markets on a roller-coaster ride lately, even as positive economic data and earnings are released. Once the trade situation between the U.S., Canada and Mexico is resolved, the U.S. will move on to squaring trade differences with China, its biggest partner.
The S&P 500 and Nasdaq closed at all-time highs on Monday. The Nasdaq also broke above 8,000 for the first time ever. Trump touted the milestone in a tweet Tuesday, saying: "NASDAQ has just gone above 8000 for the first time in history!"
"In March, we had four areas of trade uncertainty: Mexico, China, Europe and Canada. I think Canada will be resolved and Europe and Canada are already resolved," said Tom Essaye, founder of The Sevens Report. "Basically, we've got three of four resolved, but China is a big one."
Essaye also said he would be surprised if stocks keep grinding higher without a resolution to U.S.-China trade relations.
Consumer confidence rose in August to its highest level since October 2000.
Footwear retailer DSW rose more than 20 percent after reporting better-than-expected quarterly earnings. Tiffany shares also rose 1 percent on stronger-than-forecast earnings.
—CNBC's Kayla Tausche contributed to this report.