By Jing Yang and Simon Clark

A top HSBC executive signed a petition supporting China's move to impose security legislation on Hong Kong, putting the bank squarely on the side of Beijing in the fight over the future of the territory.

The global bank, based in the U.K. but whose roots and profits grow mostly from Hong Kong and Asia, had been under pressure in recent days to come out publicly over the law. The U.S., U.K. and other Western governments have strongly objected to the new law, saying it breaches an agreement that granted Hong Kong a degree of autonomy when the U.K. handed back control of the city to China in 1997.

In a post on one of HSBC's social media accounts in China, the bank's Asia-Pacific head Peter Wong is seen signing a petition in support of the law. In the post, the bank said "HSBC respects and supports any laws that stabilize the social order in Hong Kong and revitalize economic prosperity and development in Hong Kong."

"We respect and support laws and regulations that will enable Hong Kong to recover and rebuild the economy and, at the same time, maintain the principle of 'one country two systems,'" an HSBC spokeswoman in London said when asked to comment on Mr. Wong's statement.

Mr. Wong, who also chairs the Hong Kong General Chamber of Commerce, said in an interview with China's official Xinhua News Agency published on June 3, that the national security law will bring social stability in Hong Kong. "With the backing of the rapid-developing mainland market, Hong Kong's economy will definitely walk out of the clouds and get back to the development path."

HSBC has flourished in Hong Kong since British bankers established it there in 1865 to finance trade between Asia and the West. It has tried to stay out of the political turmoil in the city.

Last week, pro-Beijing former Hong Kong Chief Executive Leung Chun-ying called on HSBC to express support for the new Chinese security law in a Facebook post. His request to HSBC came a day after the U.K., U.S., Canadian and Australian governments expressed "deep concern" about China's introduction of the law.

Chinese officials have said the new law is necessary to quash separatism and foreign interference in Hong Kong, which has been rocked by antigovernment protests since last summer.

In recent decades HSBC deepened its relationship with China, opening retail branches and starting a securities venture as the country opened its financial markets. Expansions in the U.S. and other parts of the globe were less successful, and the bank has made repeated pledges to double down on Asia.

HSBC said in February that it would shed 35,000 jobs and cut business lines across the U.S. and Europe to focus on its Asian heartland.

HSBC had previously sought to avoid taking a political stance on Hong Kong by instead playing up its role as a major employer and lender supporting local economic growth. In newspaper ads last August, it called for the rule of law and a peaceful resolution to the protests.

It has been impossible to stay entirely out of the fray, though. After HSBC shut down an account used to finance protest-related causes late last year, protesters vandalized bank branches and sprayed red paint on Stephen and Stitt, a pair of bronze lions outside its Hong Kong headquarters.

The bank at the time said the account wasn't being used for its stated purpose, and the shutdown was "categorically unrelated to the current Hong Kong situation."

At an August meeting between Hong Kong Chief Executive Carrie Lam and bank and business executives, Mr. Wong was one of a few who agreed to stand with Ms. Lam at a news conference, in what was construed as political support.

The political debate over the security law leaves HSBC in a difficult position. While most of its business is in Asia, it keeps London as its headquarters and is regulated by the Bank of England. HSBC generated 90% of its pretax profit in Hong Kong last year.

Mr. Wong's petition signing came on the same day that U.K. Prime Minister Boris Johnson responded to the law by saying he would consider providing a route to British citizenship for nearly three million Hong Kong residents.

"We all know that politicians should not run banks but this shows that it is ill-advised for bankers to get involved in politics," said Alistair Carmichael, a British lawmaker who co-chairs a parliamentary group on Hong Kong. "Whatever the economic advantage that HSBC may think they obtain from this posture in the longer term they risk destroying the stable environment on which they rely," he said.

HSBC's globe-straddling profile often leaves one part of its empire unhappy. Earlier this year U.K. regulators forced all banks based in the country to cancel dividends to investors as a way to conserve capital as the coronavirus hit the country hard. HSBC had to follow along even though its largest market, Hong Kong, was reopening. This hit the bank's mom-and-pop investor base in Hong Kong hard, and its shares recently traded below their lowest level in over a decade.

Standard Chartered PLC, a London-based bank which like HSBC does a big share of its business in Asia, also voiced support for Beijing's policy in Hong Kong on Wednesday.

"We believe the national security law can help maintain the long term economic and social stability of Hong Kong," said a Standard Chartered spokesperson.

Write to Jing Yang at Jing.Yang@wsj.com and Simon Clark at simon.clark@wsj.com