BEIJING -- The Chinese government made the final decision to allow Edward Snowden to leave Hong Kong, a move that Beijing believed resolved a tough diplomatic problem even as it reaped a publicity windfall from Mr. Snowden's disclosures, according to people familiar with the situation.
Hong Kong authorities have insisted that their judicial process remained independent of China, but these observers -- who like many in this article spoke on the condition of anonymity to talk freely about confidential discussions -- said that matters of foreign policy are the domain of the Chinese government, and Beijing exercised that authority in allowing Mr. Snowden to go.
From China's point of view, analysts said, the departure of Mr. Snowden solved two concerns: how to prevent Beijing's relationship with the United States from being ensnared in a long legal wrangle in Hong Kong over Mr. Snowden, and how to deal with a Chinese public that widely regards the American computer expert as a hero.
"Behind the door there was definitely some coordination between Hong Kong and Beijing," said Jin Canrong, professor of international relations at Renmin University in Beijing.
Beijing's chief concern was the stability of the relationship with the United States, which the Chinese believed had been placed on a surer footing during the meeting between President Xi Jinping and President Barack Obama at the Sunnylands estate in California this month, said Mr. Jin and a person knowledgeable about the Hong Kong government's handling of Mr. Snowden.
The Chinese government was pleased that Mr. Snowden disclosed the extent of U.S. surveillance of Internet and telephone conversations around the world, giving the Chinese people a chance to talk about what they describe as American hypocrisy regarding surveillance practices, said Mr. Jin and the person familiar with the consultations between Hong Kong and China.
But in the longer term, China's overall relationship with the United States, which spans global economic, military and security issues, was more important than the feelings of the public in China and Hong Kong, who felt that the contractor should be protected from the reach of the United States, analysts said.
Mainland Chinese officials "will be relieved he's gone -- the popular sentiment in Hong Kong and China is to protect him because he revealed United States surveillance here, but the governments don't want trouble in the relationship," said the person familiar with the consultations between Beijing and Hong Kong. Mr. Snowden went public in Hong Kong on June 9, the day after the meeting between Mr. Obama and Mr. Xi ended, as the source of a series of disclosures in the British newspaper The Guardian and The Washington Post about classified national security programs.
The stream of information about the extent of American worldwide eavesdropping shifted the focus in the public sniping between the Obama administration and China over cybersecurity that had been unfolding for months.
In a series of speeches, senior officials in the Obama administration, including national security adviser Tom Donilon and Defense Secretary Chuck Hagel, had taken the offensive against China, publicly accusing it of cyberespionage against American businesses. Mr. Donilon said in a speech in March that China was responsible for theft of confidential business information and proprietary technologies through digital intrusions on an "unprecedented scale."
In response to those accusations, China said that it was the victim of cyberattacks from the United States.
Mr. Snowden's disclosures appeared to confirm the Chinese government's argument, and put the United States on the defensive. The highly classified documents that Mr. Snowden gave to the two newspapers showed that the National Security Agency compiled logs of virtually all telephone calls in the United States and collected the email of foreigners from American Internet companies.
Mr. Snowden has denied giving China classified documents and said he had spoken only to journalists. But his public statements, directly and to reporters, have contained intelligence information of great interest to China.
Two Western intelligence experts, who worked for major government spy agencies, said they believed that the Chinese government had managed to drain the contents of the four laptops that Mr. Snowden said he brought to Hong Kong, and that he said were with him during his stay at a Hong Kong hotel.
If that were the case, they said, China would no longer need or want to have Mr. Snowden remain in Hong Kong.