WASHINGTON (NYTIMES) – The Chinese government systematically dismantled CIA spying operations in the country starting in 2010, killing or imprisoning more than a dozen sources over two years and crippling intelligence gathering there for years afterwards.

Current and former United States officials described the intelligence breach as one of the worst in decades. It set off a scramble in Washington’s intelligence and law enforcement agencies to contain the fallout, but investigators were bitterly divided over the cause.

Some were convinced that a mole within the CIA had betrayed the US. Others believed that the Chinese had hacked the covert system the CIA used to communicate with its foreign sources. Years later, that debate remains unresolved.

But there was no disagreement about the damage. From the final weeks of 2010 through the end of 2012, according to former US officials, the Chinese killed at least a dozen of the CIA’s sources. According to three of the officials, one was shot in front of his colleagues in the courtyard of a government building – a message to others who might have been working for the CIA.

Still others were put in jail. All told, the Chinese killed or imprisoned 18 to 20 of the CIA’s sources in China, according to two former senior US officials, effectively unravelling a network that had taken years to build.

Assessing the fallout from an exposed spy operation can be difficult, but the episode was considered particularly damaging. The number of US assets lost in China, officials said, rivalled those lost in the Soviet Union and Russia during the betrayals of both Aldrich Ames and Robert Hanssen, formerly of the CIA and the FBI, who divulged intelligence operations to Moscow for years.

The previously unreported episode shows how successful the Chinese were in disrupting US spying efforts and stealing secrets years before a well-publicised breach in 2015 gave Beijing access to thousands of government personnel records, including intelligence contractors.

The CIA considers spying in China one of its top priorities, but the country’s extensive security apparatus makes it exceptionally hard for Western spy services to develop sources there.

At a time when the CIA is trying to figure out how some of its most sensitive documents were leaked onto the internet two months ago by WikiLeaks, and the FBI investigates possible ties between President Donald Trump’s campaign and Russia, the unsettled nature of the China investigation demonstrates the difficulty of conducting counterespionage investigations into sophisticated spy services like those in Russia and China.

The CIA and the FBI both declined to comment.

Details about the investigation have been tightly held. Ten current and former US officials described the investigation on the condition of anonymity because they did not want to be identified discussing the information.

The first signs of trouble emerged in 2010. At the time, the quality of the CIA’s information about the inner workings of the Chinese government was the best it had been for years, the result of recruiting sources deep inside the bureaucracy in Beijing, four former officials said. Some were Chinese citizens who the CIA believed had become disillusioned with the Chinese government’s corruption.

But by the end of the year, the flow of information began to dry up. By early 2011, senior agency officers realised they had a problem: Assets in China, one of their most precious resources, were disappearing.

The FBI and the CIA opened a joint investigation run by top counterintelligence officials at both agencies. Working out of a secret office in Northern Virginia, they began analysing every operation being run in Beijing. One former senior US official said the investigation had been code-named Honey Badger.

As more and more sources vanished, the operation took on increased urgency. Nearly every employee at the US Embassy was scrutinised, no matter how high ranking. Some investigators believed the Chinese had cracked the encrypted method that the CIA used to communicate with its assets. Others suspected a traitor in the CIA, a theory that agency officials were at first reluctant to embrace – and that some in both agencies still do not believe.

Their debates were punctuated with macabre phone calls – “We lost another one” – and urgent questions from the Obama administration wondering why intelligence about the Chinese had slowed.

The mole hunt eventually zeroed in on a former agency operative who had worked in the CIA’s division overseeing China, believing he was most likely responsible for the crippling disclosures. But efforts to gather enough evidence to arrest him failed, and he is now living in another Asian country, current and former officials said.

There was good reason to suspect an insider, some former officials say. Around that time, Chinese spies compromised National Security Agency surveillance in Taiwan – an island Beijing claims is part of China – by infiltrating Taiwanese intelligence, a US partner, according to two former officials. And the CIA had discovered Chinese operatives in the agency’s hiring pipeline, according to officials and court documents.

But the CIA’s top spy hunter, Mark Kelton, resisted the mole theory, at least initially, former officials say. Kelton had been close friends with Brian J. Kelley, a CIA officer who in the 1990s was wrongly suspected by the FBI of being a Russian spy.

The real traitor, it turned out, was Hanssen. Kelton often mentioned Kelley’s mistreatment in meetings during the China episode, former colleagues say, and said he would not accuse someone without ironclad evidence.

Those who rejected the mole theory attributed the losses to sloppy US trade-craft at a time when the Chinese were becoming better at monitoring US espionage activities in the country. Some FBI agents became convinced that CIA handlers in Beijing too often travelled the same routes to the same meeting points, which would have helped China’s vast surveillance network identify the spies in its midst.

Some officers met their sources at a restaurant where Chinese agents had planted listening devices, former officials said, and even the waiters worked for Chinese intelligence.

This carelessness, coupled with the possibility that the Chinese had hacked the covert communications channel, would explain many, if not all, of the disappearances and deaths, some former officials said. Some in the agency, particularly those who had helped build the spy network, resisted this theory and believed they had been caught in the middle of a turf war within the CIA.

Still, the Chinese picked off more and more of the agency’s spies, continuing through 2011 and into 2012. As investigators narrowed the list of suspects with access to the information, they started focusing on a Chinese-American who had left the CIA shortly before the intelligence losses began. Some investigators believed he had become disgruntled and had begun spying for China.

One official said the man had access to the identities of CIA informants and fit all the indicators on a matrix used to identify espionage threats.

After leaving the CIA, the man decided to remain in Asia with his family and pursue a business opportunity, which some officials suspect that Chinese intelligence agents had arranged.

Officials said the FBI and the CIA lured the man back to the US around 2012 with a ruse about a possible contract with the agency, an arrangement common among former officers.

Agents questioned the man, asking why he had decided to stay in Asia, concerned that he possessed a number of secrets that would be valuable to the Chinese. It’s not clear whether agents confronted the man about whether he had spied for China.

The man defended his reasons for living in Asia and did not admit any wrongdoing, an official said. He then returned to Asia.

By 2013, the FBI and the CIA concluded that China’s success in identifying CIA agents had been blunted – it is not clear how – but the damage had been done.

The CIA has tried to rebuild its network of spies in China, officials said, an expensive and time-consuming effort led at one time by the former chief of the East Asia Division. A former intelligence official said the former chief was particularly bitter because he had worked with the suspected mole and recruited some of the spies in China who were ultimately executed.

China has been particularly aggressive in its espionage in recent years, beyond the breach of the Office of Personnel Management records in 2015, US officials said. Last year, an FBI employee pleaded guilty to acting as a Chinese agent for years, passing sensitive technology information to Beijing in exchange for cash, lavish hotel rooms during foreign travel and prostitutes.

In March, prosecutors announced the arrest of a longtime State Department employee, Candace Marie Claiborne, accused of lying to investigators about her contacts with Chinese officials. According to the criminal complaint against Claiborne, who pleaded not guilty, Chinese agents wired cash into her bank account and showered her with gifts that included an iPhone, a laptop and tuition at a Chinese fashion school. In addition, according to the complaint, she received a fully furnished apartment and a stipend.