SHANGHAI/SINGAPORE, Nov 6 (Reuters) - China's attempts to keep the yuan from falling contributed to last week's chaos in money markets, sources involved say, pointing to the pressure behind the scenes as Beijing tries to guide its economy and markets through a major slowdown.

Routine month-end demand for cash in China's banking system snowballed into a scramble on Oct. 31 that pushed short-term funding rates as high as 50% in some cases, an incident that authorities are now investigating.

Six participants in the market say a confluence of factors drove fear and confusion across trading rooms in Shanghai and Beijing by late afternoon on that day.

Eventually, the People's Bank of China (PBOC), its affiliated China Foreign Exchange Trade System (CFETS) and bond clearing houses stepped in, directing lenders, extending trading hours and holding meetings with institutions to calm markets.

The contributing factors were the usual month-end demand for liquidity, cash hoarding in the lead up to a big government bond sale and a market where the biggest banks were already reticent to lend because of a mandate to counter pressure on the yuan.

"It was an accident," said Xia Chun, chief economist at wealth manager Yintech Investment Holdings, calling it an unforeseen consequence of the government's heavy hand in financial markets.

"Banks were grudging in lending, leaving non-banks asking each other for money in afternoon trade," he said. "Borrowing rates surged as a result, with some willing to take any price."

The reasons for the spike in interest rates and the ensuing market chaos are detailed here for the first time. Participants say that the vulnerability exposed will stay as long as capital outflows keep the system under pressure.

Most of them requested anonymity as they were not authorised to discuss a sensitive topic publicly.

The PBOC told Reuters that CFETS was probing "abnormal" trades on Oct. 31 involving some accounts repeatedly borrowing and lending money at "extremely high interest rates" near the end of trading hours.

'COMBAT MOOD'

Short-term financing markets, such as overnight repurchase agreements, or repos, are crucial to the daily business of banks, insurers and other financial institutions.

They affect foreign exchange movements since the markets are the major avenue for the supply of money.

Funds and non-banks borrow and roll over loans that finance their investments and trades in the repo market. The month-end is also when banks and other finance-sector participants have to square their books and comply with rules on capital buffers.

Disruptions, therefore, can threaten financial stability.

Seeds of trouble were sown in October when China approved one trillion yuan ($137.32 billion) in sovereign debt sales, to be rolled out - according to sources familiar with the plans - by sticking to the issuance schedule for the fourth quarter but increasing the size of each tranche.

Typically, said one fund manager in Shanghai, in such situations the PBOC would offset the cash drain from the extra bond issuance with extra funding support - for example by relaxing bank reserve requirements.

But putting extra cash into the system would risk adding downward pressure on the yuan - which has lost over 5% against the dollar this year - and undercut months of efforts to stabilise the currency.

"The inaction by the central bank is mainly due to its concern over yuan depreciation," said the fund manager, who declined to be identified as he was not authorised to talk to media.

On trading floors that Tuesday, the scramble for short-term funds became a stampede.

Even repo rates between banks, normally stable and the main gauge of short-term funding costs, flew from an overnight rate of 2% a day earlier to as high as 8% on Oct. 31.

DESPERATE BORROWERS

At 4 p.m. (0800 GMT) the state banks that normally lend to desperate last-minute borrowers were missing, according to three market participants.

The absence left a couple of desperate borrowers paying 30%-50% - rates not seen since defaults at China Everbright Bank and Industrial bank Co Ltd a decade ago - to secure the loans they needed.

At 5 p.m. markets closed with positions unfunded and trades incomplete.

"No one left the trading desk, as you don't know how things will go ... the whole trading room was in combat mood," said one fund manager in Beijing.

"If you need to square your positions in such an environment, and want to avoid default, you need to borrow at high rates," the fund manager said. "For each individual, it's rational behaviour."

The PBOC stepped into the breach, asking state banks to supply funds while the China Central Depository & Clearing Co (CCDC) and Shanghai Clearing House both reopened settlements at 6 p.m in an emergency response. By 8.30 p.m., crisis was averted and the market cleared and closed again.

DO NOT 'BE EMOTIONAL'

At a follow-up meeting with banks and brokers the next day, sources said the PBOC told institutions their behaviour was "disturbing the market" and that they should not "be emotional."

The money market operator CFETS told traders to keep a 5% ceiling on repo transactions and said anyone involved in high-rate deals closed on Oct. 31 would need to explain themselves to regulators, according to sources who received the notice.

Fear subsided with overnight rates falling back below 3%. To be sure, most see the danger as having passed.

But analysts have turned to the backdrop - intensifying control over China's currency - as an underlying source of tension.

China's economic rebound from the COVID-19 pandemic has been a disappointment. Together with rate rises around the world, it has fanned capital outflows and the yuan has suffered.

And yet, after dropping 5% on the dollar over the year to mid-August, the exchange rate has been conspicuously steady since as efforts from state-bank buying to new rules discouraging short selling have been deployed to support it.

Tighter liquidity is another method.

"If the pattern of money supply and liquidity provision remains unchanged, the whole system remains fragile. Another liquidity shock is always possible," said the Beijing-based fund manager.

Others see less risk, but expect tightness will stay as long as there is pressure on the currency. Broad dollar weakness has helped the yuan lately, but at 7.28 to the dollar it is not far from September's 16-year low of 7.351. ($1 = 7.2822 Chinese yuan) (Reporting by Shanghai Newsroom Writing by Tom Westbrook; Editing by Vidya Ranganathan and Raju Gopalakrishnan)