BEIJING — 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.