But the seeds of the identity crisis were planted before Mr. Xi. In the past decade, policy proposals by Beijing that aimed to impose the kind of party ideology and control familiar to mainlanders — including an antisubversion bill and the patriotic education curriculum — ignited large protests. That forced Chinese officials to shelve the plans. More recently, a ruling in August by Beijing on the 2017 election law and a report released in June that sought to redefine main elements of governance — for example, insisting that judges be patriotic — have inspired fiery criticism.

“People used to not care so much about politics, and they used to not think so much of Hong Kong as home before 1997,” said Dennis Kwok, 36, a Hong Kong-born lawyer and lawmaker who returned in 2000 and renounced his Canadian citizenship. “But since 1997, the younger people want to have a greater say in public affairs, and they think of Hong Kong as home.”

A June poll by University of Hong Kong researchers showed an increase this year in people identifying themselves as Hong Kongers, while those identifying as “Chinese” and as a “citizen of the People’s Republic of China” dropped to the lowest levels since 1997 and 2007. Those last two categories ranked last among the six ways in which the respondents could choose to identify themselves. “Asians,” “members of the Chinese race” and “global citizens” were all higher, and “Hong Kongers” was first. The university has conducted the poll every six months since 1997.

“We prefer to be ruled by a democratic country,” said Jeff Leung, 23, who was in the besieged Mong Kok tent, wearing a black T-shirt with a Union Jack on the chest. “We don’t want to be ruled by a country that massacres its own people.”

It is not only Beijing’s policies but also its alliances with local tycoons that alienate many Hong Kongers. People here also resent the growing presence of mainlanders, which has transformed the economic, social and even linguistic landscape.

Mainland businesspeople and party elites have bought real estate, driving up prices that were already among the highest in the world. That has made housing unaffordable for many in the middle class, especially for recent high school and college graduates. Mainlanders also take other coveted resources, like slots in elite schools and hospital beds in maternity wards, as women arrive to give birth so that their children can have Hong Kong residency and the related economic benefits.

Even the huge presence of Mandarin-speaking mainland tourists — derisively called locusts by some — reinforces the feeling among many Hong Kongers that the tide of another culture threatens to drown all that they say makes this city unique.