The S&P 500 and Nasdaq composite closed at record highs on Monday after a rise in tech and oil prices.
The S&P climbed about 0.5 percent, with materials leading advancers. Energy was also among the best performers after a sharp rise in crude prices.
West Texas Intermediate futures spiked 2.11 percent to settle at $48.85 per barrel after the Russian and Saudi energy ministers said the two countries agreed to extend a production cut until March 2018.
"This is a snap-back rally in crude. The rubber band had stretched too long below $55 per barrel; now we're around $50," said Joe Sowin, head of global equity trading at Highland Capital Management.
That said, an increase production from the U.S. could cap energy's gains, said Jason Pride, director of investment strategy at Glenmede. "Our Take: Oil should trade in the $50-70 range as increased demand is met by supply from U.S. share oil producers," Pride said in a note Monday.
The Nasdaq, meanwhile, was led higher by a rise in large-cap tech stocks, including Facebook and Alphabet. Shares of tech giant Apple also hit record highs.
The Dow Jones industrial average also closed higher as Cisco Systems' stock popped on the back of a massive cyberattack.
A "ransomware" virus dubbed WannaCry hit 200,000 in more than 100 countries on Friday. The virus locked up computers in car factories, hospitals and schools.
President Donald Trump ordered Homeland Security Adviser Tom Bossert to hold an emergency meeting Friday night to assess the threat posed by the attack, Reuters reported.
The PureFunds ISE Cyber Security ETF (HACK) rose more than 3 percent, putting it on track for its best day of the year.
The Dow also received a boost from Johnson & Johnson, which rose 2.71 percent after JPMorgan upgraded the stock.
Equities have traded near record levels recently as investors have shrugged off conflict in Washington that could derail the implementation of pro-growth policies as well as geopolitical tensions.
"Investors have been desensitized with all the news about North Korea and out of Washington," said Christian Magoon, CEO of Amplify ETFs. "I think it;s doing them a disservice."
North Korea said this weekend it tested a new type of missile that can carry a nuclear warhead. However, the U.S. military's Pacific Command said on Sunday the type of missile that was fired was "not consistent" with an ICBM and South Korea's military played down the North's claim of technical progress on atmospheric re-entry.
"Everything seems to slide off this market," said Bruce McCain, chief investment strategist at Key Private Bank. "Other than a potentially cataclysmic event in Washington, ... I think the slowdown in economic data" could threaten the market in the next 3-to-6 months. "In the meantime, the market continues to hold up with its Teflon curtain."
Jeffrey Saut, chief investment strategist at Raymond James, said in a note that he expects stocks to break into new records later this week, citing his models. "While our models are not always right, they are right more times than they are wrong and hereto we are tilting portfolios accordingly."
In economic news, the National Association of Home Builders survey showed sentiment among home builders came in at 70 for May. Anything above 50 is considered positive sentiment. The index was at 58 in May of last year.
Meanwhile, the Empire State manufacturing index dropped to negative 1 in May from a print of 5.2 last month.
The Dow Jones industrial average rose 85.33 points, or 0.41 percent, to close at 20,981.94, with Johnson & Johnson leading advancers and Verizon lagging.
The gained 11.42 points, or 0.48 percent, to end at 2,402.32, with materials leading nine sectors higher and telecommunications and consumer discretionary lagging.
The Nasdaq advanced 28.44 points, or 0.46 percent, to 6,149.67.
About three stocks advanced for every decliner at the New York Stock Exchange, with an exchange volume of 849.01 million and a composite volume of 3.460 billion at the close.
The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, traded near 10.4.
—Reuters contributed to this report.
On tap this week:
Earnings: Noah Holdings, DXP Enterprises
4:00 p.m. TIC data
8:30 a.m. Housing starts
8:30 a.m. Business leaders survey
9:15 a.m. Industrial production
7:00 a.m. Mortgage applications
8:30 a.m. Initial claims
8:30 a.m. Philadelphia Fed survey
1:00 p.m. Cleveland Fed President Loretta Mester
9:15 a.m. St. Louis Fed President James Bullard
Watch: Crude higher, markets up too