A federal crackdown on a network of Chinese-funded programs operating on nearly 100 U.S. college campuses led San Francisco State to shutter its Confucius Institute recently, while Stanford University’s remains in business.

For 14 years, San Francisco State’s Confucius Institute offered free Mandarin classes to employees, taught the language to thousands of kids and teachers across Northern California, hosted contests for the city school district, and delivered no fewer than 25,000 presentations on Chinese culture, the university said. It also ran an exchange program with the Beijing Normal University.

“It was such a wonderful thing we had,” said Yenbo Wu, associate vice president for international education on campus, and the institute’s former director. “You feel bad.”

San Francisco State’s program opened in 2005, among the nation’s first. More than 500 now operate around the world, a 2019 federal study shows. Typically, they offer non-credit Mandarin classes and cultural exchanges jointly funded by China and their university hosts.

But an ultimatum from the Department of Defense led eight universities from Hawaii to Rhode Island, including San Francisco State, to end their Confucius Institutes this year. They got the warning because the campuses also host a Defense Department “Chinese Language Flagship Program,” a rigorous, five-year course intended to cultivate Mandarin-fluent students for careers in national security and other government work.

The department said it would pull Flagship funding unless the campuses shut down their Confucius Institutes.

San Francisco State is the only California campus with a Defense Department Chinese Flagship program. The warning arrived Nov. 13, with an invitation to apply for a waiver that required providing copies of Confucius Institute documents. But after San Francisco State sent the documents, word came in April that no waivers would be granted.

“It is not in the national interest,” the letter said. The campus closed its Confucius Institute May 6.

The Defense Department did not respond to requests for comment, and offered San Francisco State no additional explanation for its ultimatum. It said only that “no Department funds will be used to support a Chinese language program at an institution of higher education that hosts a Confucius Institute.” The prohibition also appears in the department’s 2019 budget.

The crackdown comes at a time of rising tension between the two countries, from the ongoing trade war to government fears of Chinese espionage in academia. This spring, news reports revealed that the FBI has been urging research universities for at least a year to track visitors from Chinese schools. This week, National Public Radio reported that FBI agents have asked graduates of Peking University’s Yenching Academy if they’ve been recruited to spy.

The FBI has also kept an eye on the Confucius Institutes “for a while,” the agency’s director, Christopher Wray, told a Senate intelligence committee hearing on Russian threats to U.S. elections last year.

The institutes have long attracted criticism from politicians — usually but not always conservatives — who call them part of China’s propaganda effort. Some professor organizations have also said they interfere with academic freedom.

Stanford’s 10-year-old Confucius Institute consists of an endowed professorship in Chinese culture, two graduate fellowships and a conference and event fund. It was funded in 2009 by a $4 million gift from the Chinese Ministry of Education’s Confucius Institute office, known as Hanban, and matched by Stanford.

“Because the Hanban contribution is an irrevocable gift, they have no leverage to infringe on academic freedom at Stanford, nor have they tried,” said E.J. Miranda, a Stanford spokesman.

Inside Higher Education, a news publication, has tracked the Confucius Institute story for years. When Stanford’s program was set up, it quoted a Hanban official worrying that the endowed professor might discuss “politically sensitive things, such as Tibet.” A Stanford official responded that the university would not restrict free speech, and said, “Hanban did not walk away.”

More common is San Francisco State’s model, with a variety of cultural and educational programs. The campus split the $390,000 annual cost with Hanban.

The Confucius Institute’s most public example of censorship happened in 2014 at a conference of the European Association of Chinese Studies in Portugal. Hanban’s director, Xu Lin, reportedly had five pages removed from conference materials for referring to “Taiwanese” universities and a foundation.

The American Association of University Professors had already called on universities to end confidential contracts with Hanban and renegotiate those that ceded control over academic decisions to China. San Francisco State was among those that did so, said Wu.

“We just updated our agreements before we had to close,” he said.

Scattered other universities have closed their Confucius Institutes after political pressure.

Last year, U.S. Sen. Marco Rubio, R-Florida, pushed five campuses in his state to close their Confucius Institutes for being “a tool to expand the political influence” of China. Four complied. And U.S. Rep. Seth Moulton, D-Mass., urged Tufts University and UMass Boston to do the same. UMass Boston complied. Tufts did not.

Wu said his institute at San Francisco State was free of such influence. “These are not valid criticisms — the idea that this is a propaganda machine telling people to believe in the Chinese government,” he said. “That’s absolutely not the case.”

Charles Egan, a professor of Chinese and director of the government’s Flagship Program at San Francisco State, said it was “truly a shame that the law did not allow” the programs to coexist.

“It is undeniable that they are an instrument of Chinese ‘soft power,’” he said of the Confucius Institutes. “That is potentially a concern, yet neither I nor any of my colleagues in the Chinese program here ever noted even a trace of the actions and behaviors” ascribed to them.

Instead, he said, the institute “did fine work, had a positive impact, and will be missed.”

Nanette Asimov is a San Francisco Chronicle staff writer. Email: nasimov@sfchronicle.com Twitter: @NanetteAsimov