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.