BEIJING — Australia, a close ally of the United States, has used its embassies in Asia to collect intelligence as part of the National Security Agency’s global surveillance efforts, according to a document leaked by the former agency contractor Edward J. Snowden and published this week in the German newsmagazine Der Spiegel.

The Chinese Foreign Ministry reacted angrily on Thursday to the assertions in the document, which also said that the American Embassy in Beijing and consulates in Shanghai and Chengdu operated special intelligence gathering facilities, and it demanded an explanation from the United States.

“We demand that foreign entities and personnel in China strictly abide by the Vienna Convention on Diplomatic Relations, the Vienna Convention on Consular Relations and other international treaties, and they must not, in any form, engage in activities that are incompatible with their position and status and that are harmful to China’s national security and interest,” Hua Chunying, a spokeswoman for the ministry, said at a daily briefing for reporters.

Australia is one of the so-called Five Eyes countries that share highly classified intelligence and agree not to spy on one another; the other four are the United States, Britain, Canada and New Zealand.