Images of masked thugs massing in Hong Kong’s streets. Unproven allegations that protesters are being led by the C.I.A. Comparisons between activists and Nazis.

As protests continue to roil Hong Kong’s streets, China’s state-led propaganda machine has gone into overdrive to persuade the world that radical Hong Kong protesters have put the city in peril. Through social media and other digital arenas, English-language messages from China have painted a picture of a tiny minority of foreign-influenced ruffians intimidating a silent majority of law-and-order residents.

But instead of making China’s case, Beijing’s ham-handed international efforts have largely failed to sway world public opinion. They took a further blow on Monday, when Facebook and Twitter removed hundreds of accounts that they said appeared to be state-backed efforts to sow misinformation and discord in Hong Kong.

Perhaps more significantly, Twitter took the further step of forbidding state-run media outlets from paying to get their tweets promoted so that they appear prominently in users’ timelines. Chinese state-run outlets like the English-language China Daily newspaper and Xinhua, the official news agency, have used promoted tweets to put their own spin on Hong Kong’s turmoil.

Call it a failure of Chinese “soft power” — what the political scientist Joseph S. Nye Jr., who coined the term, defined as getting others to want what you want. China wants soft power but, judging by Beijing’s propaganda, doesn’t know how to get it.

The contrast has been stark. On Sunday, hundreds of thousands of peaceful demonstrators clogged the city streets to call once again for the city’s leaders to give in to their demands and give the people greater say in a political system controlled by Beijing. The protesters — organizers put their number at 1.7 million — offered a more sympathetic narrative than the world saw the week before, when violent clashes broke out in protests at Hong Kong’s airport.

Video

For more than two months, antigovernment protests have gripped Hong Kong, with anger rising over China’s growing influence. Here are tactics the Chinese government is using to frame the narrative.

Chinese state media, on the other hand, in recent days has shown images of Chinese paramilitary police across the border in the mainland engaged in crowd-clearing exercises. The Twitter account of Global Times, a nationalist tabloid controlled by the Chinese Communist Party, posted a video on Monday calling four pro-democracy Hong Kong figures “The Gang of Four,” a term that refers to the former Chinese leaders who were blamed for plunging the country into the disastrous Cultural Revolution. (The tweet has since disappeared.)

Pro-China activists also appeared in Australia, Canada and Europe, putting on less-than-wholesome displays. In Toronto on Sunday, pro-mainland protesters shouted words like “traitor” and “loser” as well as crude epithets at a crowd of Hong Kong supporters. One widely circulated video showed four flashy sports cars revving their engines with Chinese flags hoisted out their windows. “Worst ‘Fast & Furious’ movie ever,” said one person on Twitter.

China’s tactics may ultimately work in Hong Kong, though so far protesters appear unbowed by threats of a crackdown. And at home, where independent news sources like The New York Times are blocked, China’s propaganda push appears to be astonishingly effective. Many internet users there reacted with outrage at the images last week of a Global Times reporter who was beaten by protesters at the airport. Chinese social media is awash with the bloodied faces of police and shaky images of foreigners who state media have claimed — often wrongly — are secret protest leaders.

China is using the same tactics abroad, but in most cases, they don’t play well. These include comparing protesters to cockroaches and some cringe-inducing anti-democracy rapping. “Who are you?/Who’s hiding behind the scenes?,” go the lyrics to a rap disseminated by the foreign arm of China Central Television, the state broadcaster. “All I see is a beautiful dream turning to nightmare.”

China, since 2010 the world’s second largest economy after the United States, has been determined to build the nation’s soft power. It envies the sort of unconscious sway that the United States enjoys simply through the pervasiveness of its economic and cultural heft. President Trump isn’t going to win any trade wars because people in China love the “Transformers” movies or watch “Game of Thrones,” but American mass media and other cultural exports increase people’s familiarity and warmth with the country’s ideals.

China could use some of that sway about now. Its credibility and legitimacy are under assault in Washington and elsewhere as China hawks rise in prominence.

“It is easy to dismiss such talk as ‘slogan diplomacy,’” wrote David Shambaugh of the George Washington University in 2015. “But Beijing nonetheless attaches great importance to it.”

“We should increase China’s soft power, give a good Chinese narrative and better communicate China’s messages to the world,” Mr. Xi said not long after he became the president in 2013.

In his most important media policy speech in 2016, Mr. Xi instructed the top official media organizations to learn to tell compelling Chinese stories and build flagship foreign-language media outlets with global influences. Xinhua, CCTV, Global Times and the rest have bolstered their presence in the United States and elsewhere and taken to the very same social media outlets like Facebook and Twitter that Beijing blocks at home. Some accounts have amassed followers of over 10 million.

However, the Hong Kong protests have suggested that Beijing still knows hard power much better than soft. Instead of offering a competing narrative of a Hong Kong that could prosper under Chinese rule, it has instead made itself look like a bully.

Though troops haven’t crossed into Hong Kong, images distributed around the world by Chinese media outlets show heavily armed personnel preparing for urban conflict. Beijing is forcing businesses, both global and local, to keep their Hong Kong employees in line or risk getting cut off from the vast Chinese market. On Sunday, Beijing announced a new policy that will buff up the socialist city of Shenzhen just across the border so it can compete head-to-head with capitalist Hong Kong.

Some young mainlanders are so worked up with nationalistic fervor that they are using software to bypass Chinese censors to log into Facebook, Twitter and Instagram to blast and shame those who support Hong Kong. While that may have some effect on Chinese students living abroad, it has otherwise had little impact.

Contrast China’s approach with Russia’s: Moscow-tied groups have used social media to tremendously disruptive effect in the United States, Europe and elsewhere. But China needs to build a positive image for itself, not tear down the reputation of others.

That is in part why a recent CCTV tweet, comparing the Hong Kong protests to the Nazi rise in Germany in the 1930s, undermines Beijing more than it helps. The post quotes a rewritten version of the poem by Martin Niemöller, the church leader who opposed Hitler, which ends with, “Then they came for me — and there was no one left to speak for me.”

The People’s Daily version compares the persecution of Jews, socialists and trade unionists with protesters storming Hong Kong’s main legislative building, blocking roads and attacking reporters, including an accusation that demonstrators “trampled the freedom of the press.”

Should it continue down the same rhetorical path, China risks eroding what little soft power it has. As Mr. Nye once explained to Chinese university students, “the best propaganda is not propaganda,” because during the Information Age, “credibility is the scarcest resource.”

Hong Kong’s Summer of Protest

The semiautonomous region of China has been wracked with demonstrations.