BEIJING: Li Xiaopeng once idolized the West. While a student, he broke through China’s internet firewall to read news from abroad, revered the U.S. Constitution and saw the authoritarian Chinese government as destined to fade away.

Now the 34-year-old urban consultant, who studied at both Cambridge and Harvard, thinks it’s China that is ascendant and the U.S. that is terminally weakened by income inequality, divided government and a polarized society. He says so volubly to his more than 80,000 followers on social media. “In the end, China will supplant America to be the world’s No. 1 strong country,” he wrote on Weibo, China’s homegrown version of Twitter .

President Xi Jinping is holding up China as a confident global power at a time when U.S. leadership seems uncertain. Increasingly, his government can count on swelling national pride among its own citizens.

A generation after China’s late reformist leader Deng Xiaoping exhorted his fellow citizens to “keep our light hidden and bide our time,” Chinese exceptionalism is on the rise. While some Chinese still believe the country will need to embrace democracy to reach its full potential, many others are convinced the country has reached this point, not in spite of the government’s crushing of pro-democracy protests in 1989, but because of it.

Annual surveys by the Pew Research Center since 2010 show more than 80% of Chinese are satisfied with the direction of their country. Three-quarters of the Chinese surveyed by Pew last year see China playing a bigger role in global affairs than 10 years ago, and 60% view China’s involvement in the global economy as positive.

On his blog, between digressions on Socrates and Ming Dynasty economic policy, Mr. Li writes at length on the superiority of the Chinese political system. Unlike the U.S., where he says charisma is prized over professionalism and money is needed to win office, he argues that China promotes officials based on their performance in spurring economic growth and managing large cities and bureaucracies.

“Among people in my generation, there aren’t many of us now who think we should totally study the West,” says Mr. Li. “To them, China is already a great country.”

The sense that China is on the right track challenges a decades-old tenet of U.S. foreign policy, one that argued exposure to the West would lead Chinese to embrace Western values.

In the wake of Brexit and Donald Trump’s election, and amid global fears about terrorism, a generation of Chinese patriots like Mr. Li are projecting an assurance about China as a beacon of strength and stability in an uncertain world.

President Xi’s signature slogan, the “China Dream,” appeals to Chinese who aspire to a middle-class lifestyle and cheer China’s return to international prominence. On the global stage, Mr. Xi has portrayed China as an alternative to the West, with a unique political system and culture, and as a leader in areas including trade, inequality and climate change.

“What people are starting to feel is pride. It’s the pride of being listened to, or forcing people to listen to you,” says Orville Schell, director of the Center on U.S.-China Relations at the Asia Society. “The idea of greatness for China – because they’ve experienced weakness – gravitates around the idea of power.”

China’s government exercises near-absolute authority over education, media and the internet. That, along with determined campaigns to quash dissent, give the Communist Party unparalleled power to frame public debate. As a result, patriotism and pro-government views are amplified. Criticisms tend to get drowned out.

After communications professor Deng Xiangchao posted messages on Weibo in December lamenting the millions who died in Mao Zedong’s political campaigns, he was hounded online as a “public enemy,” saw his account deleted and was fired by Shandong Jianzhu University for “erroneous remarks.”

Writer Lu Yang protested the professor’s treatment at the hands of “a gang of ignorant internet goons” in online posts. His Weibo account was also expunged. “The space for free speech in China grows smaller by the day,” says Mr. Lu.

A spokesman for Weibo said he wasn’t clear on the circumstances surrounding the closure of accounts belonging to Deng Xiangchao and Lu Yang.

More-aggressive forms of nationalism are usually directed at foreign countries seen as standing in China’s way. After South Korea agreed to deploy a U.S. antimissile system as protection against North Korea, Beijing condemned the move as endangering Chinese security. Soon some Chinese began posting videos online showing themselves trampling goods from South Korean stores in China. A beef-noodle shop in Beijing advertised that it wouldn’t serve South Koreans.

Chinese businesses, students and tourists crisscross the globe in record numbers, and international news features prominently in the media. More than anything, Chinese say, their current patriotic sentiment is built on pride about how rapidly the country has emerged from poverty and how well its economy compares with others.

In seven out of 10 European countries surveyed by the Pew Research Center, including the U.K. and Germany, China is now considered the world’s leading economic power, according to data released in July. The gap in global popularity between the U.S. and China has also narrowed dramatically in recent years, with 47% of people now expressing a positive view of China, compared to 49% for the U.S., according to Pew.

A record 328,547 Chinese students were enrolled in the U.S. in the 2015-2016 academic year, up 160% from six years prior, drawn to the quality of the higher education system and eager to bypass China’s grueling college-entrance exams.In the past, most would stay on after graduating. Now around 80% choose to return home, where, many say, better job prospects await.

A small survey of 131 Chinese students studying in the U.S., Europe, Australia, Japan and South Korea published in 2014 in the journal China Youth Study found that while most weren’t markedly patriotic before leaving China, close to 80% reported feeling more patriotic after going abroad. Roughly two-thirds said they agreed with Mr. Xi’s “China Dream.”

Chen Hesheng, a 22-year-old recent college graduate, spent a month in a summer study program at the University of Southern California in Los Angeles in 2014. Two Chinese graduate students were gunned down while sitting in aBMW near campus in 2012. He felt scared to go out at night and shocked at the U.S.’s poor public safety.

Mr. Chen resents the preaching from the U.S. and other Western governments about democracy and human rights: “Young people aren’t convinced that the West is better. Who are you to tell us that it is?”

These days, Mr. Chen is part of a generation of patriotic online activists known as “little pinks” – named for the background color of a website known for passionate, patriotic political discussions.

Like others in this mostly millennial cohort, Mr. Chen says the internet and travel enable them to see China more accurately. He leaps internet barriers mostly to watch uncensored videos on YouTube and occasionally to counter what he sees as inaccurate views about China on Facebook. In 2016 he twice joined swarms of mainland activists in posting tens of thousands of pro-China comments on the Facebook pages of Taiwan’s president and media outlets seen as favoring the democratically ruled island’s formal independence from China – long a hot-button issue for patriotic Chinese.

For Chinese students in the West who take positions that offend their fellow citizens, blowback can be swift. In May, a Chinese graduate at the University of Maryland sparked a furor of online criticism after she praised free speech and America’s air quality in a commencement address. Even the country’s Foreign Ministry weighed in on the controversy, declaring that “any Chinese citizen should be responsible for the remarks he or she makes.” The student later publicly apologized, saying she hadn’t meant to belittle her home country.

For Mr. Li, the urban consultant, his experience overseas was formative. As a child in rural Sichuan, he lived in a home without running water. Rice was rationed. School closed so students could help with the harvests. Visiting relatives meant walking for hours through fields. Still, he was raised to be grateful to the Communist Party. His parents, a schoolteacher and a shop worker, gave him Mao’s collected writings to inspire him.

After his high score on the politics portion on the college entrance exam landed him a spot studying law at one of the nation’s top schools, Beijing’s Renmin University, his world view began to change. His more liberal teachers brought their ideas into classroom discussions. “They’d say China has no rule of law, no human rights,” he recalls. He had internet access in his dorm room and used circumvention software to reach sites outside China to read uncensored news and commentary. “They said that Mao Zedong was a despot, and that China’s ancient history was one of autocratic rule,” he said.

The more Mr. Li learned, the more his certainties about his society crumbled and the more he came to admire the West, with its wealth, its respect for civil liberties and its political checks and balances. He devoured works on the U.S. legal system. The Watergate scandal’s toppling of Richard Nixon impressed him. “We thought the West’s political system was really good, and that we should use it to change China,” he says. That change would surely come, he says: “We thought it was just a question of time.”

Doubts about the West crept in when he spent a half-year at the University of Cambridge as part of his doctorate in economics. Compared with China’s brand-new infrastructure, the buildings in most British cities looked shabby. Getting a bank card took days.

A year at Harvard University’s Kennedy School as a visiting fellow starting in 2010 accelerated his change in thinking. He was appalled at the number of panhandlers in subway stations and how unsafe he felt.

The U.S. was just emerging from a financial crisis that left China largely unscathed. Amy Chua’s “Battle Hymn of the Tiger Mother,” which extolled the benefits of hard-line Chinese parenting, became a best seller. “If Americans admire China so much, maybe the way we saw China before wasn’t so accurate,” he thought.

He sifted through U.S. census data found online and concluded inequality was weakening America. He saw its divided political system as too in thrall to special interests to serve the broader public.

“For decades, America’s politicians have come and gone, and put forward pleasant-sounding slogans about how they’ll promote the middle class and social equality. But basically, it’s a bad check,” he wrote on his blog in December. In a separate posting, he extolled China’s scientific achievements, including its No. 1 spot in supercomputing, as evidence of the country’s burgeoning strength. “It’s astonishing the world!” he wrote.

Seeing the West up close, Mr. Li says, was a defining experience for him. He’s fond of citing an expression now common among Chinese youth: Once you leave your country, you love your country. “If you don’t go abroad, you don’t actually know how great China is,” says Mr. Li.