U.S. stocks climbed Monday as investors scooped up some of the technology stocks that came under pressure to start the year.

The tech-focused Nasdaq Composite Index gained 271.05 points, or 1.9%, to 14532.55, while the S&P 500 added 36.78 points, or 0.8%, to 4582.64. The Dow Jones Industrial Average rose 103.61 points, or 0.3%, to 34921.88.

The indexes have rallied over the past three weeks after the Federal Reserve raised interest rates for the first time since 2018 in a bid to curb inflation. The S&P 500 and the Dow industrials are about 5% below their January highs, while the Nasdaq is off about 10% from November’s record.

Twitter shares led the S&P 500, surging $10.66, or 27%, to $49.97, after Tesla Chief Executive Elon Musk reported that he held a stake of 9.2% in the social-media company as of March 14. Twitter added $8.53 billion in market value, its largest one-day gain on record.

Mr. Musk asked his followers last month whether they believe Twitter upholds free speech, adding “The consequences of this poll will be important. Please vote carefully.”

Meanwhile, Tesla shares gained $60.86, or 5.6%, to $1,145.45.

Other technology shares also climbed. Meta Platforms added $9.04, or 4%, to $233.89. Netflix gained $18.03, or 4.8%, to $391.50, and Alphabet rose $56.42, or 2%, to $2,859.43. All three stocks are still in the red for 2022.

Tech and other growth stocks have lost some of their allure as the Fed raises rates. Higher rates place a premium on corporate earnings now, which tends to make shares of firms whose profits may lie in the future less attractive.

Investor sentiment continues to track the war in Ukraine, with many watching whether new reports of war crimes will add to pressure on the Biden administration and European allies to tighten sanctions on Russia. Analysts say pressure on the West to ban Russian oil is gathering steam. The reports come amid peace talks currently under way between Kyiv and Moscow and could complicate those discussions.

“Given all the uncertainty that’s still out there, I’m a bit surprised at how strong the equity market is,” said Altaf Kassam, head of investment strategy for Europe, the Middle East and Africa at State Street Global Advisors. “The long-term consequences of the conflict will be higher inflation over the long term.”

Oil prices rose amid questions about whether European nations may shift away faster from Russian energy and if Russian President Vladimir Putin will halt gas deliveries to Europe over demands for payment in rubles. Meanwhile, plans by Western nations to release oil from their reserves and lockdowns in Chinese cities have pulled back energy prices from recent highs. Brent-crude futures, the international benchmark, added $3.14 a barrel, or 3%, to $107.53.

A surge in prices for oil and other raw materials has contributed to the Fed’s plans to raise rates. However, as the Fed embarks on its lifting campaign, investors are worried that the removal of monetary stimulus and ultralow interest rates could threaten the rally in equities.

“The market is looking at: Where will economic growth be? What will it do to corporate earnings and then how much leeway does the Fed have to deal with inflation?” said James Ragan, director of wealth management research at financial services firm D.A. Davidson Co.

In other corporate news, shares of Starbucks fell $3.40, or 3.7%, to $88.09 after the company said it is suspending billions of dollars in share repurchases, a move that interim CEO Howard Schultz said would free up cash to invest in cafes and employees. Lifestyle and culture company Hypebeast is bringing its stock to the U.S. through a merger with blank-check company

Iron Spark I, whose shares were up 17 cents, or 1.7%, to $10.17.

Hertz Global Holdings agreed to purchase up to 65,000 electric vehicles over five years from the Swedish auto maker Polestar, part of the rental-car company’s goal of expanding its plug-in offerings. Hertz shares rose $2.26, or nearly 11%, to $23.38.

In the bond market, the yield on the two-year Treasury note remained above that of the 10-year note Monday. In that situation, the yield curve is said to be inverted, something that is often viewed as a predictor of recessions.

The yield on the benchmark 10-year Treasury note edged up to 2.409%, the highest yield in about a week. Two-year yields, which are more sensitive to expectations of short-term interest rates, stood at 2.426%. Yields rise as bond prices fall.

“We want to start thinking about where the puck is going and potentially looking at more defensive positioning, but again we’re not there [recession] yet because of this unusual environment,” said Emily Roland,

co-chief investment strategist at John Hancock Investment Management. Ms. Roland said the backdrop of elevated inflation, economic reopening and possibly decelerating global growth could still lead to gains in stocks.

Traders worked on the floor of the New York Stock Exchange on Friday.

Photo: Michael M. Santiago/Getty Images

The pan-continental Stoxx Europe 600 added 0.8%. 

Major indexes in Asia closed with gains. South Korea’s Kospi rose 0.7%, and Japan’s Nikkei 225 edged up almost 0.3%. Markets in mainland China were closed for a holiday. 

Hong Kong stocks led gains in the region. Technology stocks were among the biggest advancers, boosted by hopes that a potential compromise by China over audit inspections could help avert the eventual delisting of U.S.-listed Chinese stocks. The Hang Seng Tech Index gained 5.4%, while the city’s main Hang Seng Index rose 2.1%. 

Over the weekend, the China Securities Regulatory Commission proposed removing a requirement that domestic regulators take the lead in inspecting the audit papers of overseas-listed Chinese companies. Market watchers said the proposal could be a step toward a deal with the U.S. Securities and Exchange Commission.

More broadly, investors were taking the view that many markets had started to offer good value after a recent selloff, said Dwyfor Evans, head of macro strategy for the Asia-Pacific region at State Street Global Markets.

“We’re certainly not seeing the out-and-out risk aversion that we were a few weeks ago,” Mr. Evans said.

—Clarence Leong contributed to this article.

Write to Caitlin Ostroff at caitlin.ostroff@wsj.com