Over the weekend, some 800,000 protesters poured into Hong Kong’s streets to register their discontent with Communist China’s encroachments on their liberties and rule-of-law traditions. The mass of people stretched across miles in the densely packed territory, testifying to the pro-democracy movement’s enduring strength.

The movement has already forced the Hong Kong government to grant its initial demand — the permanent withdrawal of a bill authorizing extraditions to mainland China. So what’s the endgame?

Few observers believe that Hong Kong people can indefinitely escape an increasingly hard-line Beijing. China, after all, maintains the world’s largest military. The Communist behemoth has no qualms about massacring its way out of domestic turmoil, as it showed in 1989. China is big and armed; Hong Kong, small and defenseless.

Still, the people in the territory hold high cards.

For starters, Hong Kongers are united, something that was evident in local elections last month. With a record 71.2 percent turnout, the pro-democratic camp won 389 of 452 seats. Beijing’s ­establishment lost control of 17 of the 18 local councils, holding on to one of them only because of a law providing for government-appointed members.

The sheer size of the protests is another sign of Hong Kong unity. In the evening during Sunday’s massive rally, people of all ages walked peacefully, their cellphones held aloft, light against the darkness.

At lunchtimes, Hong Kongers gather in shopping malls to sing their adopted anthem, “Glory to Hong Kong.” Ordinary residents drive to violent nighttime demonstrations to pick up black-clad youth and ferry them to safety. People in the territory don’t have the look of a defeated population.

Despite what many think, Chinese paramount leader Xi Jinping doesn’t have a feasible military solution. Young demonstrators dressed in riot gear are determined to fight, and they are supported by an overwhelming share of the population.

These youth would prove an extremely difficult guerilla force for China to overcome. In Hong Kong, every apartment building is a fort. The kids in black can harass, trap and kill Chinese soldiers and then melt into their homes.

Xi surely doesn’t want his first war to require tens of thousands of troops, take years and end in defeat, as it might.

At the same time, he won’t make the compromises necessary for a political solution. The protests have gone on for so long, because whenever they were losing steam Beijing has done something — ­either directly or through despised city Chief Executive Carrie Lam — to renew the energy.

Plus, as the struggle continues, global public opinion is forming ­behind Hong Kong. That support is best symbolized by President Trump, who, in the face of public Chinese threats, signed a pair of pro-Hong Kong bills into law late last month.

There are now rallies around the world, each with a “Lennon Wall” dedicated to the territory’s stand against China. At any moment, you can find pro-Hong Kong graffiti on Stuttgart subway cars, protests in Washington, DC, mini-uprisings by pro-Hong Kong students on the campuses of Canadian universities. And so on.

In short, Beijing feels constrained in what it can do to bring a defiant Hong Kong to heel.

Then there are China’s internal headaches: demographic decline and an exhausted environment to name just two — but most immediately, a slumping economy made worse by long-term trade friction with its most important customer, the United States.

Historically, Chinese regimes have unraveled from the outside in, and Hong Kong, on China’s southern coast, could be the inspiration for the next wave of societal-wide unrest, such as the violent protest in nearby Wenlou at the end of last month.

The Communist Party can still prevail, to be sure, but there are reasons to hope that Hong Kong will remain a vibrant and free ­society. Beijing officials these days say Hong Kong is irrevocably part of “red China,” but the mere fact that they keep repeating that slogan shows they are in fact worried.

Gordon G. Chang is the author of “The Coming Collapse of China.” Twitter: @GordonGChang