Stocks rose on Monday, recovering losses from earlier in the session as oil dipped despite rising geopolitical worries following last week's U.S. killing of Iran's top general.
The Dow Jones Industrial Average ended the day up 68.50 points, or 0.2% at 28,703.38 after falling 216 points earlier in the day. The S&P 500 closed 0.4% higher at 3,246.28 while the Nasdaq Composite advanced 0.6% to 9,071.46.
Big tech stocks led the gains. Facebook and Amazon both rose more than 1%, and Netflix and Google-parent Alphabet advanced 3.1% and 2.7%, respectively.
Monday's gains were in contrast to Friday's sharp decline. The Dow and S&P 500 had their worst trading day in a month on Friday, the morning after President Donald Trump approved a U.S. airstrike in Baghdad that killed top Iranian Gen. Qasem Soleimani.
"If you were looking for a reason to sell, you got one," said Art Hogan, chief market strategist at National Securities. "But the fundamental backdrop hasn't changed in front of our eyes."
"The market has done exactly what it should do," he added.
The news sparked a bid on oil prices amid worries the conflict could disrupt the world's oil supply. Crude rallied more than 3% on Friday to its highest level since April. Oil briefly rose 2% earlier in Monday's session before settling little changed.
Trump said Sunday he could slap sanctions on Iraq after its parliament passed a resolution calling for the government to expel foreign troops from the country. "We have a very extraordinarily expensive airbase that's there. It cost billions of dollars to build. Long before my time. We're not leaving unless they pay us back for it," Trump said.
Iran said Sunday it would not abide by the uranium-enrichment limits set by the 2015 nuclear deal.
Investors have loaded up on traditional safe havens such as gold and Treasurys as U.S.-Iran tensions rose.
On Monday, gold futures hit their highest level in more than six years. The benchmark 10-year Treasury yield hovered around 1.8% after starting 2020 trading above 1.9%. Yields move inversely to prices.
"Nevertheless, our outlook remains optimistic and bullish," Ed Yardeni, president and chief investment strategist at Yardeni Research, said in a note. "Geopolitical crises tend to create buying opportunities in the stock market as long as they don't trigger a recession."
"We don't believe that Iran will disrupt oil supplies significantly now that the US has demonstrated a willingness to use lethal force to deter Iran's mischief-making in the Middle East," Yardeni added.
Alphabet shares climbed to an all-time high after an analyst at Pivotal Research upgraded them to buy from hold. The analyst cited new potential revenue streams under new CEO Sundar Pichai.
—CNBC's Silvia Amaro contributed to this report.