MACAO — Macao, the world’s gambling capital, is becoming more intertwined with a Chinese neighbor — one person, train and building at a time.

A former Portuguese colony, Macao was returned 25 years ago to China and declared a special administrative zone, part of the mainland but with some independence. Beijing agreed to mostly keep its hands off the 12-square-mile territory.

Like nearby Hong Kong, Macao would be part of China but free to govern itself and run its economy without interference from Beijing. It quickly rose to become the world’s most lucrative gambling destination, drawing big American casinos and catering to mostly Chinese tourists.

Now China’s political experiment in Macao is undergoing another transition. China’s leader, Xi Jinping, who visited Macao last month to mark the anniversary of the territory’s “return to the motherland,” wants Macao to operate less independently of mainland China. In Xi’s vision, Macao will wean itself off an economic reliance on gambling and play a role in boosting China’s own lagging consumer economy.

At the heart of this new push is Hengqin, a Chinese island separated from Macao by a river. In a sprawling new immigration complex at Hengqin Port, officers for China and Macao sit side by side, waving people over a new border. More than 16,000 Macanese citizens have moved to Hengqin in recent months. A train made its debut journey from the city into Macao in December. There is even talk of creating a Macao Stock Exchange in its financial district.

Beijing has given Macao more land to expand in Hengqin, eased restrictions on Chinese tourists traveling to Macao to gamble at its casinos and offered the casinos favorable investment policies to build resorts and conference centers in Hengqin.

Xi’s treatment of Macao, with a population of 700,000 people, stands in contrast to his approach in Hong Kong, where in 2019, millions of people protested moves to make the territory more like the rest of China. Beijing responded by imposing a tough national security law and jailing pro- democracy leaders.

“Macao has followed the directive from the central government, the people have accepted it and there hasn’t been much protest or noise from the community,” said Larry So Man-yum, a retired professor of social work at Macao Polytechnic Institute. The preferential policies in Hengqin for Macanese citizens “are like candies for well-behaved children,” he said.

In many ways, Macao needs China. It has little space to build new industries and housing, and its government derives most of its revenues from one industry — casinos. Its water supply comes from a river that flows into the Pearl River in China.

At the same time, Beijing needs Macao. It is the only place in China where gambling is legal. Macao offers Chinese tourists a destination where they can let off steam and explore remnants of the territory’s four centuries under Portuguese rule.

Macanese businesses have been asked to cough up money to build attractions like entertainment centers and resorts in Hengqin, as part of a broader Chinese project known as the Greater Bay Area, which is merging and blurring the boundaries between major southern Chinese cities as well as Hong Kong.