HONG KONG — Tens of thousands of demonstrators marching peacefully in one of several authorized rallies on Sunday were dispersed with tear gas, ending a rare and cherished period of peace in Hong Kong amid half a year of pro-democracy protests.

The march in Tsim Sha Tsui on the Kowloon side of the city had a clear message: the five demands of the protest movement, including universal suffrage and an investigation into the Hong Kong police, are not to be forgotten.

Protesters, who included the elderly and children and some of whom were carrying banners calling for the end to the Chinese Communist Party, said their fight must go on despite several key successes for the movement.

Voters in district elections overwhelmingly chose pro-democracy candidates who now control 17 out of Hong Kong’s 18 electoral districts, widely seen as a resounding message of support for the pro-democracy cause. President Trump has also signed into law a bill designed to support pro-democracy protesters after a huge bipartisan push.

“We feel better because of the election and the bill, but that’s not the end of the protest,” said Eric Chan, 33. “We need to bear in mind that we have a lot of demands which we cannot forget, and if we forget these demands, our friends, our comrades who have died or been prosecuted, their sacrifice would be for nothing.”

The rally was legal and approved by authorities, but some protesters appeared to veer off from the path sanctioned for their march. Others also hurled insults and made vulgar signs at the police, a continuation of deep tensions between many in Hong Kong and security forces which they believe are acting with impunity. By the late afternoon, shots of tear gas had been fired, sending the crowd scattering and coughing.

In a statement, police said the protesters did not follow the approved route and attacked officers.

“As some radical protesters passed by Mody Road Garden via Salisbury Road, they hurled bricks at Police officers. Police officers, in response, deployed the minimum necessary force, including tear gas, to stop their illegal acts,” according to the statement.

Protests were sparked back in June after a government proposal to allow extraditions to mainland China, in what many felt would mark an end to Hong Kong’s prized freedoms and autonomy. The government has since withdrawn that proposal, meeting one of the five demands of the protest movement.

The unrest has only grown, however, and revived a long-held demand for full, direct elections in the territory above the district level.

In recent months, protests have intensified and grown more violent. Mid-November saw a tense, new phase when demonstrators tried to fortify two university campuses against police raids — leading to an intense standoff at both.

At Polytechnic University, where protesters rained molotov cocktails and arrows down on police, authorities sealed off all entrances and warned protesters that anyone inside would be arrested and charged with rioting.

That led to daring, risky attempts at escape from bridges and sewers, while others barricaded themselves on campus. The siege finally ended this week and a cleanup has begun. Authorities say it could take up to six months.

That exceptionally dangerous new period, during which police had threatened to use live ammunition, has been followed by a stretch of peace in Hong Kong. Many saw the election as a rare opportunity for them to express their democratic will, and no tear gas was fired in any district for over a week until this weekend.

By sundown, police began clearing protesters gathering in the area and made several arrests.

“We have requested for a permit to hold the assembly and it won’t expire for a few hours, but they are already scaring us away,” said Kenton Cheung, 32, as police used their shields and batons to clear off peaceful demonstrators. “I don’t know what’s their intention, why they are always creating this intense environment in which we can’t express ourselves.”

He added: “Police have initiated this conflict, that’s why people have fought back.”

An independent investigation into the police conduct has been one of the main demands of protesters, with authorities countering that existing oversight mechanisms were sufficient to detect any problems. Chris Tang, the new commissioner of police who just took over this month, called any inquiry into police behavior “unjust.”

The United Nations High Commissioner for Human Rights Michelle Bachelet published an opinion piece in the South China Morning Post Saturday urging an independent investigation into the charges of police brutality as part of an inclusive dialogue.

“I appeal to the government to take important confidence-building measures, including a proper independent and impartial judge-led investigation into reports of excessive use of force by the police,” she wrote.

China’s U.N. mission in Geneva on Sunday called the comments “inappropriate” and accused Bachelet of interference in the country’s internal affairs and said her article would only “embolden the rioters” to engage in more violence.