Hong Kong announced on Sunday that Carrie Lam, the candidate viewed as most favored by Beijing, will be the special-status territory’s new chief executive, the first woman to fill that position. She won 777 of the 1,163 valid votes cast, the returning official said, a result that is likely to shore up Hong Kong’s perception that China isn’t adhering to the “one country, two systems” policy that entitles the former British colony to greater freedom and political choice than prevails in the mainland.

Despite active campaigning that saw the city’s former finance secretary John Tsang become the favorite in polls of public opinion, and that political observers said was likely intended to have a behind-the-scenes effect on Beijing’s heart and mind, he secured just 365 votes. The third candidate, retired judge Woo Kwok-hing, got 21 votes.

“The election committee result is one that is directly contradictory to the majority public opinion of the Hong Kong people,” lawmaker Dennis Kwok, a lawmaker and member of the Civic Party, which advocates for greater democracy in Hong Kong, told reporters. “It is regrettable that they have decided to exercise their vote that way. It will simply make governing Hong Kong much more difficult in the next five years.”

Some voters registered their unhappiness with the process by casting blank ballots, or writing profanities on them.

Outside the election venue, pro-democracy and pro-Beijing protesters gathered, sometimes playing competing music, according to the Hong Kong Free Press, a publication that was barred from the press area because of being online only.

Activist Ken Tsang, who began serving a five-week term last week for assaulting police and resisting arrest during the Occupy protests in 2014, voted from behind bars, a first for the leadership election, reported the South China Morning Post. The demonstrations that year came in opposition to Beijing’s proposed changes to the chief executive election system, which many here saw as diluting a reform that was supposed to usher in universal suffrage.

Reuters/Bobby Yip Carrie Lam, left and Woo Kwok-hing, center, look on as officials open ballot boxes.

But overall the line-up of voters Sunday morning shaking hands with the candidates captured the common complaint that Hong Kong’s tiny circle of electors in the leadership elections—1,194 people out of nearly 3.8 million registered voters—mainly represents the city’s elites. While most families don’t even have a single vote, tycoon Li Ka-shing, Hong Kong’s richest man, and his two sons, Victor Li Tzar Kuoi and Richard Tzar Kai, each got to cast a ballot.

Meanwhile, a Facebook live-stream offered glimpses of how Hong Kong’s many, many nonvoters spent Sunday.

Lam, who was until recently Hong Kong’s number two official, will take office in July, succeeding the unpopular Leung Chun-ying at a time when Hong Kong will also be marking the 20th anniversary of its return to Chinese sovereignty.

On Sunday, she pledged to heal Hong Kong’s divisions and “unite our society to move forward.” In the run-up to the election she spoke of making housing more affordable and spending more on education.

Linda Che-lan Li, a professor of politics at City University of Hong Kong whose research has focused on conflict and collaboration, said that Ms. Lam should patiently pursue the approach of trying to talk with opposing camps—even if it doesn’t appear to be yielding immediate results.

“I hope she will not be perturbed if she is not received in a positive manner” right away, said Professor Li, “This is something that all of us have to learn—that is, how to come out from an election, come out of an electoral campaign, and then not to allow all these feelings of opposing one another to linger too long.”