HONG KONG — When Alan Yau was growing up in the Hong Kong of the 1990s and 2000s, it was a city where identity was rooted in worldliness and prosperity. People felt free to consider themselves Hong Kongers, Chinese and world citizens all at once.

But lately, many have shifted to a more closed, inward-looking identity, said Mr. Yau, a researcher at the Chinese University of Hong Kong. Flags and anthems, symbols of national-style identity that were once of little use to those in his cosmopolitan social circles, have become increasingly common.

Hong Kongers had always been proud, but there is something new: a feeling of besiegement, and from much more than mainland China’s authoritarian leaders.

Hong Kong’s eruption into monthslong protests may have been the result not only of Beijing’s overreach, but also of seismic changes in Hong Kong identity itself, according to new research and opinion polling.