Hong Kong (CNN Business) Beijing is stepping up the battle to stop money flowing out of China as the country contends with economic woes and trade war tensions that have eased but show no sign of ending altogether.

Money was leaving the country at a record clip earlier this year through unauthorized channels, according to analysts. That's bad news for China, which needs to keep financial reserves high to maintain confidence in its markets.

Now Chinese officials are trying harder than ever to avoid a repeat of the financial scare four years ago that sapped its money reserves by hundreds of billions of dollars.

The State Administration of Foreign Exchange, a key government regulator, said Sunday that its most important job next year is to prevent major financial risks, avoid "abnormal" capital flows across its borders and crack down on illegal trading activities.

"We need to fight a critical battle" to defuse financial risks and maintain market stability, SAFE said in an statement

The pledge was an unusually strong one for the agency, which deployed the kind of military language more often used by top leaders in China.

Cracking down

The agency has already started cracking down on capital flight. In November, it fined Chinabank Payments $4.2 million — one of the largest-ever fines SAFE has imposed — for moving money overseas. The regulator didn't say how much had been transferred, but it could have been tens of millions of yuan because China calculates fines based on the amount of money in question.

JD.com JD The online payments firm, a subsidiary of billionaire Richard Liu's, told CNN Business that the transfers were made by "external merchants" who had taken advantage of loopholes. But it said it felt "deeply sorry" and would reflect on its management.

Bank of China BACHF Major corporations aren't the only ones linked to the flight of money out of China. Earlier this month, acustomer took out $50,000 in cash from his bank account over the course of a week. SAFE fined the bank nearly $6,000 for breaking a government rule limiting how much foreign currency people can take out of their accounts within a short period of time.

While the amount was small, it still symbolizes how far the government is willing to go to crack down on such withdrawals.

"Controls on outflows are increasingly tight," said Alicia Garcia Herrero, chief economist for Asia Pacific at Natixis Bank.

Fleeing money

The threat of fleeing capital stems from concerns about the country's economy , which has been hurt by cooling domestic demand and a prolonged trade war with the United States.

A weaker currency, though, raises the risk that people will try to move money out of the country, which in turn threatens to drive the yuan's value even lower.

The Chinese government has been able to stop some money from leaving. About $74 billion left China through regulated channels in the first half of this year — the smallest amount in a decade, wrote Gene Ma, head of China research for the Institute of International Finance, in an October report.

Even so, a record amount of funds have left China through "unrecorded transactions" during that time, he said. The Washington-based trade group estimates that $131 billion left China in the first six months of 2019 — the most recent data available — through "hidden capital outflows." (People can move money through such means, for example, by asking friends and family to pool the annual limit on foreign currency they are allowed to withdraw from Chinese banks, or by claiming to make investments overseas that don't really exist.)

Ma wrote that the surge was triggered by "intensifying trade tensions."

China has also been trying to help its economy by cutting benchmark interest rates , which will likely increase the amount of money leaving China, said Herrero, the Natixis Bank economist.

And while China and the United States recently agreed to a "phase one" trade agreement that could cool tensions between the two countries, Herrero said that deal isn't likely to alleviate the pressure on China entirely.

She said the yuan's respite might be "temporary," adding that China's central bank will likely let the currency depreciate again if the deal is not signed, or is eventually watered down.

Lessons learned

China has good reason to keep its money in the country. The last time China experienced this kind of capital flight was in 2015 and 2016, when the economy faltered and the People's Bank of China suddenly devalued the yuan , roiling global financial markets.

On average, the amount of money leaving China was equivalent to 6% of the country's GDP in each of those two years, according to an estimate by the Chinese Academy of Social Sciences, a government think tank. In total, China lost $1.28 trillion, and it was forced to tap into its foreign exchange reserves to prevent its currency from rapidly depreciating even further.

China's foreign reserves shrank by more than $800 billion in those two years before recovering some losses in 2017. Since then, Beijing has significantly tightened control of capital and made it more difficult for people to exchange money for foreign currency or transfer funds abroad.

"Chinese regulators have learned their lessons during the frightening period of 2015-16," analysts from Bank of America wrote in November.

Analysts at UBS also pointed out that China has taken steps to offset capital flight. They noted earlier this month that the country recently opened up its financial markets further to attract foreign investors and companies. Those kind of measures can boost interest from foreign investors in the Chinese market and attract more money within the country's borders.