The Chinese government made the final decision to allow Edward J. Snowden, the former National Security Agency contractor, to leave Hong Kong on Sunday, 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.
(Read More: US Warns Countries Against Snowden Travel)
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 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 American 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.
(Read More: US Files Charges Against Snowden in NSA Surveillance Case)
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.