By Elias Glenn and John Ruwitch

BEIJING/SHANGHAI (Reuters) - China reported a surprise increase in June foreign exchange reserves on Thursday, but analysts said they could fall again in coming months if the weakening yuan triggers more capital outflows.

Even as the yuan slides to 5-1/2 year lows against the dollar and the economy struggles, official data suggest speculative capital flight is under control for now, thanks to the country's capital controls.

But analysts and financial markets widely expect the yuan to weaken further in coming months, risking a surge in outflows like those seen in 2015 and early this year.

China's foreign exchange reserves rose $20 billion in June to $3.21 trillion, recovering from a five-year low in May, central bank data showed on Thursday. June's increase was the biggest in 14 months.

Economists polled by Reuters had predicted reserves would fall $20 billion to $3.17 trillion, reckoning on sharp drops in the value of China's sterling and euro holdings following Britain's shock vote last month to leave the European Union.

But the turmoil which followed also boosted safe-haven currencies such as the dollar and the yen.

"The increase was not entirely surprising. The change in foreign exchange reserves reflect valuation effects with the strong Japanese yen...," said Raymond Yeung, senior economist at ANZ in Hong Kong.

Though the yuan ended the second quarter with its biggest quarterly fall on record, Yeung said outflows of foreign currency largely dried up in June due to capital controls.

However, economists are divided over how much money is still flowing out of the country, with opaque policymaking and some inconsistency in the data raising suspicions that the fall in the yuan may be masking capital outflow pressure.

"Capital outflows have been continuing at pace and they are a lot larger than what the authorities would have us believe through the official data," said Sue Trinh, Hong Kong-based head of Asia FX strategy at the Royal Bank of Canada.

Over-invoicing of China's imports from Hong Kong, seen as a proxy for speculative outflows, is at record highs, she said.

Data from Chinese banks also does not appear in the official foreign exchange reserve data.

"The reserves are only what the central bank does, and China can direct intervention (in currency markets) via state banks...which is why forex reserves are not a great proxy for intervention activity even though people want to draw a very hard line between the two," said Trinh.

The yuan has fallen roughly 3 percent against the U.S. dollar since March, adding to uncertainties for investors already rattled by Brexit and slowing global economic growth.

Chinese sources recently told Reuters the People's Bank of China (PBOC) was willing to let the yuan fall to 6.8 to the dollar by the end of the year to support the economy. That would mark a depreciation of 4.5 percent in 2016, matching last year's record decline.

After that report, the PBOC said China had no intention to promote trade competitiveness through depreciation of the yuan, a comment also made repeatedly by Chinese Premier Li Keqiang.

Bets on further declines in the yuan hit a five-month high in the last two weeks on expectations that the central bank will allow it to weaken further, a Reuters poll showed.

Capital Economics said evidence exists the PBOC continues to defend the currency, but that pressures have clearly eased since the start of the year.

"There is little doubt that the flows remain much more manageable than in late-2015 and early-2016, when China was witnessing outflows of over $120 billion per month," analysts Julian Evans-Pritchard and Mark Williams said in a note.

"Nonetheless, if the PBOC continue to let the renminbi (yuan) slide against the dollar, there is a risk that more serious concerns over the trajectory of the currency could re-emerge, leading to another surge in capital outflows."

(Reporting by Beijing Monitoring Desk and Elias Glenn in Beijing and John Ruwitch in Shanghai; Editing by Kim Coghill)