By Anna Isaac

U.S. stocks wavered Tuesday as investors gauged the risks posed by fresh coronavirus lockdowns to the economic recovery and rebalanced portfolios on the final day of the second quarter while locking in gains.

The S&P 500 rose 0.2% shortly after the opening bell, with the index on track to end the quarter having erased most of its losses from the first three months of the year. The Dow Jones Industrial Average was flat and the Nasdaq Composite added 0.2%.

In Europe, the pan-continental Stoxx Europe 600 was down 0.4%. Equities across Asia rallied, and most major benchmarks closed for the day up sharply.

Fresh data pointing to a strengthening recovery in China's manufacturing sector was clouded by investors trying to determine whether governments' new restrictions could be enough to prevent health-care systems from being overwhelmed, while posing less of an economic cost than prior shutdowns.

"China's economic data was pretty strong, driving up Asian stocks and offering some comfort to other markets as well," said Seema Shah, chief strategist, at Principal Global Investors. "But the resurgence of the virus in the U.S. and new restrictions will be the main focus for investors."

U.S. stocks are likely to "see a slow consolidation" in coming weeks, rather than a strong rally or a sharp correction, said Ms. Shah.

A gauge of U.S. consumer confidence, measured by the Conference Board, is likely to offer fresh insights into American households' willingness to spend money and drive the economic recovery. That reading is due out at 10 a.m. ET.

"The key data at the moment are anything that offers insight on consumer confidence," said Ms. Shah. "If people start to see localized lockdowns and that weighs on confidence, it will weigh on the recovery."

Cases of new infections alone won't be enough to gauge the economic impact of the virus going forward, analysts and economists said.

"Authorities have much more experience now than in March and April," said Holger Schmieding, chief economist at Berenberg Bank. "Targeted measures such as closing crowded bars and face masks, plus a change in behavior, will avoid a New York or Northern Italy-style overstretch of the health care systems," which is the key risk facing financial markets, he said.

Earlier this week, authorities in Florida, Texas, California and Arizona -- the states that have accounted for much of the recent rise in U.S. cases -- imposed new restrictions and retreated on reopening plans. In the U.K., the city of Leicester was placed under severe restrictions Monday after data showed it had elevated infection levels relative to the rest of the country.

The CBOE Volatility Index, also known as the fear gauge, rose 1.9% to 32.40. While still elevated compared to the end of 2019, the measure is on track to fall nearly 40% this quarter, after rising sharply amid the broad-based sell off in March.

Shares in U.S. chip maker Xilinx rose 4.6% after it lifted its guidance, noting higher-than-expected revenue during the June quarter.

Ride-hailing company Uber's shares added 3.3%, after it emerged that it was in talks to buy Postmates for approximately $2.6 billion, according to people familiar with the matter.

Boeing shares fell 4.1% after Norwegian Air Shuttle said it is canceling its orders for 92 of Boeing's troubled 737 MAX jets. The company's shares are down nearly 40% this year so far, according to FactSet.

Meanwhile, Royal Dutch Shell wrote down the value of its assets by up to $22 billion on Tuesday, citing lower oil and gas price forecasts. Shell said it expects benchmark Brent oil prices to average $35 a barrel this year and $60 a barrel in the long term. Its shares fell 2% in London.

Brent crude futures, the international oil benchmark, fell 1.5% to $41.21 a barrel. U.S. crude futures fell around 1.6% to $39.08 a barrel

Over in Asia, fresh signs emerged Tuesday that China's economic recovery is picking up steam with the lifting of the coronavirus-related lockdowns. Exports and services benefited from government support policies and the reopening of some overseas markets, official data showed, though the world's second-largest economy remains far from a full recovery. An official gauge of China's factory activity rose to a three-month high in June, marking four straight months of gains.

The Shanghai Composite Index, which tracks Chinese stocks, rose 0.8%. Elsewhere in Asia, Japan's Nikkei 225 benchmark was among the biggest gainers, closing up 1.3%.

Federal Reserve Chairman Jerome Powell on Tuesday is expected to tell Congress the reopening of the U.S. economy -- and the accompanying upturn in spending and hiring this spring -- has happened sooner than central bank officials expected. The push to lift restrictions on commercial activity carries other risks, especially in terms of keeping the virus in check, he said in testimony prepared to deliver before lawmakers at 12:30 p.m. ET.

Write to Anna Isaac at anna.isaac@wsj.com