SYDNEY — Chinese students poured into Australia and New Zealand in the hundreds of thousands over the past 20 years, paying sticker prices for university degrees that made higher education among both countries’ top export earners.

Now, as a more-authoritarian China projects its influence deeper into the South Pacific, attempts by Chinese students and diplomats to interfere with anti-Beijing dissidents and stifle free speech on campuses pose an uncomfortable challenge for both U.S. allies.

The immediate trigger for the flare-ups was mass protests in Hong Kong, which authorities in the semiautonomous Chinese territory are struggling to contain. Protesters there have assailed what they say is the steady erosion in Hong Kong’s rule of law, aided by the city’s pro-Beijing leaders.

Students, academics and officials in Australia and New Zealand, two of the modern world’s older democracies, now find their natural sympathy for Hong Kong’s protesters colliding with their nations’ economic dependency on Beijing — a weakness the Chinese Communist Party isn’t hesitating to exploit.

The most visible flash point is on campus. At universities in the Australian cities of Sydney, Melbourne, Brisbane and Hobart, and in New Zealand, students who support and oppose the Chinese Community Party have spent recent days erecting, ripping down and restoring walls covered with cards and Post-it notes calling for freedom in Hong Kong.

“Beijing’s influence on campuses is responsible for widespread self-censorship by universities and academics in Australia and New Zealand,” said Clive Hamilton, a professor of public ethics at Charles Sturt University in Canberra, Australia, and the author of “Silent Invasion: China’s Influence in Australia.”

“The events of the last couple of weeks on Australian campuses have proved to be a serious escalation of Beijing’s interference,” Hamilton said.

Every pro-democracy protest is countered by Beijing’s well-drilled student supporters. When some University of Sydney students proposed a protest Friday — which did not proceed — opponents shared notes on WeChat, the Chinese messaging and social media platform, about how to respond.

“The pro-Hong Kong independence demonstration on August 9 is planned by some forces of Sydney University,” one person wrote, according to an image taken by a student. “We will not use force, but will absolutely not sit idly by and do nothing. [We] will fight the separatist forces to the end using legal means. Never make a concession!!”

The person, who could not be reached for comment, added in the message that they had “reported this to the education section” of the Chinese Consulate.

After years of feeling fortunate about their economic relationship with China, Australians are starting to worry about the cost. On Thursday, a ruling party lawmaker, Andrew Hastie, compared China’s expansion to the rise of Germany before World War II, suggesting it posed a direct military threat.

“Like the French, Australia has failed to see how mobile our authoritarian neighbor has become,” Hastie wrote in the Sydney Morning Herald.

Hastie’s comments ricocheted between Beijing and Canberra, where the Chinese Embassy condemned the former officer in Australia’s Special Air Service Regiment, an elite army special forces unit.

“We urge certain Australian politicians to take off their ‘colored lens’ and view China’s development path in an objective and rational way,” an embassy spokesman said. “They should make efforts to promote mutual trust between China and Australia, instead of doing the opposite.”

Australia and New Zealand are attractive targets for Chinese influence and espionage operations, analysts say, particularly as the smallest members of the Five Eyes intelligence-sharing alliance that includes the United States, Britain and Canada.

Paul Buchanan, a strategic analyst based in Auckland, said New Zealand is an “ideal liberal democratic lab rat” for China to experiment with ways to use “the very freedoms and transparency of democratic systems against them.”

Chinese diplomats in Australia and New Zealand appear to be encouraging confrontations by praising counterprotesters.

On July 29, a student at New Zealand’s Auckland University was confronted by a group of men who objected to her involvement in adorning a protest site, known as a “Lennon Wall,” with messages of support for Hong Kong’s demonstrators.

Cellphone footage uploaded to social media showed one of the men moving aggressively toward the student, who fell to the ground.

Three days later, the Chinese Consulate General in Auckland published a statement that appeared to support the actions of the alleged assailant and his companions, conveying its “appreciation to the students for their spontaneous patriotism,” while condemning unnamed people for “inciting anti-China sentiment.”

Protests and counterprotests have taken place since, and participants say they have received threatening messages from unknown senders.

Defenders of free speech say the episodes are a wake-up call. New Zealand Prime Minister Jacinda Ardern said last week that officials have reminded their Chinese counterparts that New Zealand “will uphold and maintain our freedom of expression.”

Standing up for such values comes at the cost of worsening relations with Beijing, the top trade partner of both countries and a lucrative source of funds for universities, which lack the big endowments of U.S. colleges. China’s purchases of iron ore, coal and dairy products have helped power Australia’s and New Zealand’s prosperity.

The University of Queensland, where punches were thrown at a Hong Kong sympathy protest recently, is so close to Chinese authorities that it appointed the Chinese consul general in Brisbane a visiting professor of language and culture last month.

The consulate then praised the “patriotic behavior” of 300 pro-Beijing students after the violent incident, prompting Australia’s defense minister to warn foreign diplomats against interfering in free speech.

The university has said that it is committed to freedom of expression on campus.

Among themselves, mainland Chinese students share advice on how to attract sympathetic coverage in confrontations with the left-wing activists they call the “baizuo,” a pejorative term for Western liberals that translates as “white left.”

“UQ students please be calm, don’t resort to violence,” said a recent post on Weibo, China’s Twitter-like service. “Try to learn from the tricks of those pro-Hong Kong independence activists. If you push me I will fall over. Fake tumble, cry and wail, call campus police. We are too strong, which won’t work in the world of baizuo.”

“It’s very tense,” Drew Pavlou, one of the student organizers of the University of Queensland protest, said in an interview. “It doesn’t feel safe. I have had to have security walk me to some classes.”

In New Zealand, an event commemorating China’s 1989 suppression of pro-democracy protests at Tiananmen Square scheduled for June 3 was moved away from Auckland University of Technology after pressure from Chinese officials.

Emails obtained through freedom-of-information requests by the online outlet Newsroom revealed that China’s vice consul met with the university’s president on May 31 to request that the event be scuttled. The university received emails from the consulate on the matter, too.

University spokeswoman Alison Sykora denied that the commemoration, which was held in a different location off campus, was abandoned because of diplomatic pressure.

In Australia, officials are so concerned about Chinese influence that the attorney general has asked his department to examine why 14 Confucius Institutes — Chinese-funded education units within Australian universities — have not been registered as agents of foreign influence under a new law directed at Chinese espionage, influence and propaganda.

At the University of Canterbury in Christchurch, New Zealand, a Confucius Institute shares a building with the office of Anne-Marie Brady, a professor who has researched Chinese government influence. Brady has complained of threats, break-ins at her home and attempted sabotage of her car. Police investigated but were unable to identify a culprit.

Reflecting a growing unease that Australia’s economic future depends on an unpredictable adversary, former prime minister John Howard said last week that unrest in Hong Kong “perhaps represents a glimpse of the future for Chinese society.”

“If you’ve been born into relative affluence and comfort, you take that for granted and you resent being told how to run your life,” he said. “Perhaps over the next 50 years, we’re going to see just how all of that works out.”

Stoakes reported from Christchurch, New Zealand. Yang Liu in Beijing contributed to this report.