The popular 14th-century Chinese novel “Water Margin” romanticizes some of the gangs’ Robin Hood-like exploits. By the 19th century, these groups embodied anti-foreign sentiment and extolled ethnic-Han identity, as well as endorsed religious or even revolutionary agendas — all the while pursuing criminal activities.

The biggest of the secret societies, known as Hong Men (洪門 or Torrential Gate), appeared in the late 17th century, originally in opposition to Manchurian invaders from the northeast. Long connected with diaspora Chinese, it has deep roots in Chinatowns throughout the world. Some of its chapters in the United States raised funds and bought weapons for the revolution of 1911: One of its members, Sun Yat-sen, founded the Republic of China, on Western democratic principles. (Sun’s protégé Chiang Kai-shek was, for his part, supported by the Green Gang of Shanghai, which engaged in the opium trade, prostitution, gambling and extortion — and helped Chiang suppress the labor unions.)

For decades, Hong Men was strongly anti-Communist and pro-Taiwan. After coming to power in 1949, the Communist Party suppressed the triads in China: Monopolies on power also do not suffer competition. But as China began to unleash economic reforms in the late 70s, especially outside the mainland, much of Hong Men became pro-Beijing. At first, the group was softened by the prospect of trade and other lucrative opportunities; later, by Han nationalism, which it shared with the Communist government.

Hong Men has a long history in Hong Kong. Many of the triads in the city are loosely identified with the organization, if only as informal, self-appointed local chapters — with tens of thousands of adherents.

Some triads, especially those operating in the Yuen Long area, became close to the Hong Kong ruling class after Britain handed the city over to China in 1997. Today, they exert influence partly through connections with local representative bodies set up to defend the interests of residents whose families have long lived in Hong Kong — groups that, in turn, weigh heavily in the process by which Hong Kong’s chief executive is selected. As such, these have been courted, mostly with business opportunities, by the China Liaison Office in recent years.

Local media have reported that in February 2012 close associates of the politician C.Y. Leung, then a candidate to become chief executive, attended a dinner with well-known members of a triad, and that they were seeking the men’s support for Mr. Leung. Mr. Leung did become chief executive later that year and the alleged connection dogged him. (He has sued or threatened to sue several publications for defamation over this claim, including one I long wrote for and another I sometimes contribute to.) Two of the people said to have been present at that dinner — nicknamed Shanghai Kid and Nga Nga (Baby) — are thought to be leaders of Wo Sing Wo. Members of the group are among the white shirts who attacked pro-democracy protesters and bystanders on July 21.

The Yuen Long police didn’t just fail to stop the violence that recent evening; according to witnesses, the rampage unfolded for more than half an hour before the police arrived. And then officers seemed mostly to stand around or mill about — or, in some cases, mingle amiably with the armed attackers. Many victims’ calls to the city’s emergency number went unanswered.