By Chao Deng

Gains baffle many analysts, who suspect government intervention

China's shares ended higher Wednesday, with sharp gains in the last half-hour of trading, as officials stepped up efforts to calm markets.

The Shanghai Composite gained 3.4%, ending at 3789.16, after flitting between gains and losses earlier. The smaller Shenzhen Composite rose 4.1% to 2198.81.

The gains--which ranged across sectors--follow three days of selling that knocked 11% from China's main stock index. Shanghai remains down more than a quarter from its June high.

Hong Kong's Hang Seng Index ended up 0.5% while a gauge of Chinese companies listed in the city rose 0.9%.

About 400 stocks listed in Shanghai and Shenzhen reached their 10% upward daily limit on Wednesday, while industrial stocks like CRRC Corp., China Railway Group and China Shipbuilding Industry Co. led gains for the Shanghai Composite.

The rapid gains late in the afternoon baffled many analysts, some of whom suspect the government may have stepped in to buy more shares.

"Clearly it is government intervention again," said Jacky Zhang, an analyst at BOC International.

Officials have come out to soothe investor concerns amid the second bout of selling this month. On Tuesday afternoon, China's securities watchdog said it would investigate whether a coordinated dumping of shares sparked Monday's selloff. Late Monday, the regulator said it would increase its support to the market.

"The market must generate a wealth effect so that investors can regain confidence," said Tang Yonggang, an analyst at Shenwan Hongyuan Securities, adding that state-backed funds may be getting diverted to infrastructure and military stocks.

Still, many investors remain cautious. The bulk of Wednesday's gains came and hour and a half before the market's close at 3 p.m. local time, with a sharp surge within the last 30 minutes. Shanghai swung wildly on Tuesday too, with the benchmark vacillating in a 6% band, though it ended the day off just 1.7%. On Monday, the market dropped 8.5%, its biggest daily fall in more than eight years.

In the wake of the volatility, investors opened 390,600 new stock trading accounts in the week ended July 24, down 26% from the previous week, according to the database CEIC, citing the China Securities Depository and Clearing Corporation. They opened 1.64 million accounts in the week ending May 29, the recent peak.

The latest round of heavy selling appears to have further flushed out borrowing by investors to make bigger bets on the market. Margin financing fell to 1.38 trillion yuan ($222.26 billion) Tuesday, the lowest since March 19, according to the latest data by Wind Information Co, from 1.43 trillion yuan on Monday. Borrowing to buy shares--or margin lending--helped fuel a yearlong rally, but also exacerbated the rout as investors sold shares to cover losses.

Still, hundreds of billions of yuan remain in the form of margin financing from unofficial lenders, such as Internet-financing platforms that authorities are looking to monitor more closely.

While most global markets have been insulated from the erratic swings in Chinese stocks in recent weeks, the moves nevertheless have stoked fears about whether a rout in the world's second-largest economy will weigh on global growth. Investors also are considering the impact of an expected rise in U.S. interest rates, as the Federal Reserve ends its two-day policy meeting Wednesday.

Read: China's stumbling stock market won't trip up U.S. earnings (http://www.marketwatch.com/story/why-chinas-stumbling-stock-market-wont-trip-up-us-earnings-2015-07-28)

"Economic growth concerns underpin most concerns regarding equities, and as such, there remains much to fear regarding China--and also the U.S. as the Fed plans to raise interest rates soon. The impact of China on Fed policy will be on close watch," said Yoshihiro Okumura, general manager at Chibagin Asset Management.

Disappointing earnings in Japan helped pushed the Nikkei Stock Average down 0.1% on Wednesday. Meanwhile, South Korea's Kospi was flat and Australia's S&P ASX 200 rose 0.7%.

Several commodities, which have been battered by a stronger U.S. dollar and worries about China's slowdown, continued to slide. China is one of the world's largest consumers of oil, metals and food, and a stronger dollar makes commodities more expensive for foreign buyers, as many are priced in the U.S. currency.

Brent crude , the global oil benchmark, fell Tuesday to its lowest price since January amid concerns about glut. Crude oil futures were last down 57 cents at $52.73 a barrel. Both Brent and the U.S. oil benchmark recently entered bear markets--defined as a 20% drop from a recent high.

Expectations the U.S. will raise interest rates soon has tarnished gold, which has hit multiyear lows in the past week, as investors consider moving to higher-yielding assets. Spot gold is roughly flat in Asia trade at $1,096.10 an ounce.

Read: Rout in gold tells us the world is changing (http://www.marketwatch.com/story/gold-sends-the-markets-a-message-2015-07-28)

Yifan Xie and Bradford Frischkorn contributed to this article.

Subscribe to WSJ: http://online.wsj.com?mod=djnwires