Stocks ended higher Monday, recovering losses from earlier in the session as oil dipped despite rising geopolitical worries after last week’s U.S. killing of Iran’s top general.

The Dow closed up 68 points after falling 216 points earlier in the day. The S&P 500 finished 0.35% higher, while the Nasdaq advanced 0.56%.

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, a 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 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 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, the 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.