A person knowledgeable about the Hong Kong government’s handling of Mr. Snowden said Sunday evening that he was sure that Hong Kong officials had consulted with the Chinese government on how to handle the case. The rough consensus in Beijing is that Mr. Snowden’s presence in Hong Kong posed a threat to Chinese-American relations after President Xi Jinping has tried to improve them, said the person, who spoke on the condition of anonymity because of diplomatic sensitivities.

Yet public opinion in Hong Kong and mainland China has made it impossible simply to send him back to the United States, the person said.

“We can’t force him to leave, the best we can do is induce him to leave,” said the person, adding that Mr. Snowden had decided to leave on his own.

The basic issue for Beijing was that public opinion in Hong Kong and mainland China was clearly shifting toward protecting him from the United States. 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,” the person said.

The result had been a policy driven by expedience, in which Beijing and Hong Kong both wanted Mr. Snowden to leave even though officials in both places deeply and sincerely appreciated what he had done to expose American intelligence activities on their soil. “It may not be the most honorable thing, but it is true,” the person said.

The Hong Kong government was dismayed that the United States chose to include espionage in its charges against Mr. Snowden, because that created clear complications under the bilateral agreement between Hong Kong and the United States for the surrender of fugitives. The agreement specifically excludes the surrender of fugitives from political cases.

“If they really want him back, they wouldn’t have put that in — they would have just put that he stole something,” said the person knowledgeable about the government’s handling of the case.

Another person in Hong Kong with a deep understanding of Hong Kong’s relationship with Beijing agreed that the mainland Chinese government and the Hong Kong government were both hoping Mr. Snowden would leave, although both were reluctant to take any direct action to push him out. “It saved both sides possible embarrassment if he left,” said the second person, who was not involved in the Snowden decision but knew intimately the institutional framework in which the decision was made.

Hong Kong’s laws prescribe that the Chinese government control Hong Kong’s foreign policy. So no decision to let Mr. Snowden leave would have been made without consulting the Chinese government, said the second person, who also insisted on anonymity because of diplomatic sensitivities. “This must have been done in full consultation with Beijing,” the second person said.

By exposing American surveillance in Hong Kong and mainland China, Mr. Snowden has already done much for China, while holding on to him could have created a serious diplomatic problem, the second person said. “Beijing has gotten the most they can out of the Snowden situation,” the second person said.

— KEITH BRADSHER