By Karen Langley and Joe Wallace

A climb in shares of Pfizer boosted the Dow Jones Industrial Average Wednesday after the US. government agreed to pay the drugmaker and partner BioNTech to secure doses of their experimental Covid-19 vaccine.

The blue-chip index gained 165.44 points, or 0.6%, to 27005.84. The S&P 500 added 18.72 points, or 0.6%, to 3276.02, and the tech-heavy Nasdaq Composite edged up 25.76 points, or 0.2%, to 10706.13.

Pfizer shares rose $1.87, or 5.1%, to $38.56. Under the $1.95 billion agreement, the U.S. will receive 100 million doses of the vaccine, after it is cleared by regulators, and can also acquire another 500 million doses. The vaccine is set to enter late-stage testing this month.

Investors have welcomed any signs of progress toward a vaccine that could allow economic activity to resume without a subsequent rise in infections. Drugmakers stand poised to benefit: The U.S. also has vaccine deals with other companies, including AstraZeneca.

"The experts were telling us, back in February, March and April, it's going to be five years before we see a vaccine, and here we are with some possible good news on vaccine that's going to hit this year," said Phil Orlando, chief equity market strategist at Federated Hermes. "I think the market is taking that very favorably."

Corporate earnings remained a key focus for investors Wednesday, with some of the technology companies that have driven much of the stock market's recovery since March reporting quarterly results after the close.

Microsoft reported strong growth in quarterly sales driven by strength in its cloud-computing segment. Its shares fell more than 2% in after-hours trading. Shares have climbed 34% this year.

Tesla for the first time reported a fourth-consecutive profitable quarter. The electric-vehicle maker's shares have soared in recent months, in part on increased expectations that it would report a fourth straight quarterly profit, which would qualify Tesla to be considered for inclusion in the S&P 500. Its shares rose more than 4% in after-hours trading.

During Wednesday's session, shares in Snap dropped $1.54, or 6.2%, to $23.20 after the company reported slowing revenue growth for the second quarter. Shares in Spotify Technology rose $13.24, or 4.8%, to $289.62 after The Wall Street Journal reported that the streaming company had reached a new licensing agreement with Vivendi's Universal Music Group.

HCA Healthcare's shares gained $13.09, or 12%, to $122.42 after the company reported higher profit in the second quarter.

"In general, the low bar, or at least the lower expectations going into Q2 -- actual earnings reports have been beating that hurdle, so perhaps that's been also adding to the momentum or the optimism that we're seeing in the markets," said Amy Kong, chief investment officer at Barrett Asset Management.

Wednesday's moves came after China's Foreign Ministry said the U.S. had instructed China to close its consulate in Houston. That raised the specter of an escalation in tensions between the world's two largest economies and prompted Beijing to condemn the move as outrageous and unprecedented.

The rising tension weighed on markets overseas. The regional Stoxx Europe 600 index fell 0.9%. Hong Kong's flagship Hang Seng Index dropped 2.3%.

Among investors' concerns: Senate Majority Leader Mitch McConnell said Tuesday that Congress is unlikely to pass a new fiscal stimulus bill quickly. The White House and Senate Republicans are struggling to bridge divisions on a payroll-tax cut, school funding and other issues.

"We are cautiously optimistic that they will reach a decision and will spend money prudently but appropriately to allow the economy to continue to recover back toward some semblance of normalcy," said Nancy Prial, co-CEO and senior portfolio manager at Essex Investment Management.

The yield on the benchmark 10-year Treasury note slipped to 0.595% -- its lowest close since April 24 -- from 0.606% Tuesday, according to Tradeweb. Yields fall as bond prices rise.

--Xie Yu contributed to this article.

Write to Karen Langley at karen.langley@wsj.com and Joe Wallace at Joe.Wallace@wsj.com