Mr. Xi and his wife, Peng Liyuan, arrived in Hong Kong shortly after noon on Thursday, disembarking from an Air China jet. They strolled down a red carpet, where they were greeted by the city’s departing chief executive, Leung Chun-ying, and Carrie Lam, who will be sworn in Saturday to succeed Mr. Leung as Hong Kong’s top government official. Tung Chee-hwa, Hong Kong’s first chief executive after the resumption of Chinese rule in 1997, was also present.
As attendees waved the red flags of Hong Kong and China, Mr. Xi spoke briefly about the importance of the city to China.
“Hong Kong has always affected my heart,” he said. “In two days, it will be the 20th anniversary of Hong Kong’s return to the motherland. This is a major event, a happy event, for the nation and for Hong Kong.”
Saying that he was happy to be in Hong Kong for the first time in nine years, Mr. Xi added that he hoped to experience the changes and development that have occurred in Hong Kong since his last visit.
Reporters on the tarmac shouted questions to Mr. Xi about Chinese rule and whether the Nobel laureate Liu Xiaobo, who was recently moved from prison in northeast China to a hospital for cancer treatment, would be released. Mr. Xi did not respond.
Later in the afternoon, Mr. Xi met with Mr. Leung and praised his work over the past five years, particularly in “defending national sovereignty and security.”
Mr. Leung was the target of fierce criticism during the Umbrella Movement protests in 2014, and many demonstrators called for his resignation. Mr. Leung refused and said at the time that the protests were aided by “external forces,” but he did not offer evidence.
Mr. Xi may encounter something he rarely sees in China: open protests. Because of its status as a semiautonomous region, Hong Kong has long allowed demonstrations, which are not tolerated in mainland China. To that end, the police have taken pains to keep protesters away from Mr. Xi’s scheduled public appearances. Roads will be closed on Saturday in the busy Wan Chai and Admiralty areas as he presides over the swearing-in of Hong Kong’s new chief executive.
The local news media reported that roughly a third of Hong Kong’s 29,000-member police force would be deployed to protect the president, his wife and the events at which they appear. But Mr. Xi’s personal security will be handled by Troop 8341, according to The South China Morning Post, which noted that the elite, secretive unit was composed of combat-ready troops.
In a video posted this week, the Hong Kong police sought to justify the extraordinary lengths to which they have gone to shield Chinese and local officials from planned protests.
The police said the security measures reflected their concerns over terrorist attacks.
“Recently, the world has been shocked by terrorist attacks of cars plowing into crowds,” an officer said in the video. “These ‘water barriers’ can ensure the safety of the public and the important officials.”
But the barriers are more likely meant to shield the leaders from expected protests. “Does that mean that all the people of Hong Kong are terrorists?” one Facebook user commented.
Mr. Wong, perhaps the best-known leader of the pro-democracy Umbrella Movement, and more than two dozen other activists were arrested Wednesday night and remained in police custody on Thursday. It was unclear whether they would be released before the protests and ceremonies on Saturday. The police can usually keep them for up to 48 hours without charges.
They were arrested for climbing the Golden Bauhinia Statue commemorating Hong Kong’s return to Chinese rule. The statue is in the square where the Chinese president will attend a flag-raising ceremony on Saturday.
“Genuine universal suffrage! Free Liu Xiaobo unconditionally!” they chanted as hundreds of mostly mainland Chinese tourists looked on.
Shocked by the display of defiance — such free expression is severely restricted in mainland China — many tourists immediately took out their phones to take photographs and videos, even though many had never heard of Mr. Liu.
“Who is Liu Xiaobo?” a woman from Anhui Province, in east-central China, asked when I approached her. “This is so scary.”
“God Save the Queen” was played by a band of Scots Guards in tall, bearskin hats, and the Union Jack was brought down.
After a five-second pause, time for British cymbals to stop vibrating, the Chinese national anthem was played and the Chinese flag raised alongside the new flag of Hong Kong.
Nicholas D. Kristof considered how mainland China would be shaped by the return: “Most analysts predict that China in 20 years’ time will look more like Hong Kong today than Hong Kong will look like China today.”
Still, not everyone thinks that Hong Kong will have much impact on China’s political system, in part because the Chinese leadership is so adamant about stopping the buds of political pluralism before they even sprout.
“Hong Kong will change China,” said Robin Munro, the head of the Hong Kong office of Human Rights Watch. “I’m sure we’ll see more venality and appetite for moneymaking. But I doubt that this means more democracy and liberalism. My biggest anxiety is that I believe that China will probably change some of the assumptions of political science in the West.”
The Basic Law, an agreement signed 20 years ago by Britain and China, says that Hong Kong will retain a high degree of autonomy, and its capitalist financial system and independent legal structure, for 50 years.
Critics say that in recent years Beijing has been undermining the spirit if not the letter of the Basic Law by cracking down on press freedoms in Hong Kong and meddling in the selection of the territory’s leaders.
Here is the text of the Basic Law governing Beijing’s relationship to Hong Kong, which says the territory “will enjoy a high degree of autonomy, except in foreign and defense affairs which are the responsibilities of the Central People’s Government.”