Image caption Protests against the classes brought tens of thousands of people out onto the streets

The Hong Kong government has backed down over plans to make schoolchildren take Chinese patriotism classes, after weeks of protests.

City leader Leung Chun-ying said the classes would be optional for schools.

"The schools are given the authority to decide when and how they would like to introduce the moral and national education," he said.

Critics said the plans were an attempt to brainwash the city's children by the Chinese government in Beijing.

The government had said the subject was important to foster a sense of national belonging and identity. Anti-Beijing sentiment has been on the rise in semi-autonomous Hong Kong, a city of seven million people.

Analysis The demonstrations highlight growing unease with Chinese rule, and the slow pace of democratic reforms on the mainland. They culminated in a hunger strike outside government headquarters this week. The widespread opposition to the compulsory curriculum had boosted the fortunes of pro-democracy legislators hoping to win a landmark election on Sunday. A strong showing by democrats paves the way for the introduction of universal suffrage in Hong Kong by 2017 at the earliest. That is why eyebrows rose when, on the eve of the polls, the government suddenly announced it would back down. Some speculated it was a move directly timed to influence the election in favour of pro-government and pro-Beijing lawmakers.

The decision comes ahead of elections on Sunday, when voters will elect just over half the members of a legislative assembly that is expanding from 60 to 70 seats.

The BBC's Juliana Liu in Hong Kong says the protests had given a boost to pro-democracy legislators hoping to win a landmark election on Sunday.

The government's surprise announcement has led some to speculate it is a move directly timed to influence that election in favour of pro-government legislators, our correspondent says.

Mr Leung, who was sworn in as Hong Kong's chief executive in July, cancelled his trip to the Apec regional summit this weekend because of the furore.

Freedom

The proposed curriculum, which consisted of general civics education as well as more controversial lessons on appreciating mainland China, was due to be introduced in primary schools in September and secondary schools in 2013.

According to AFP news agency, course material funded by the government extolled the benefits of one-party rule, equated multi-party democracy to chaos, and glossed over events like the Tiananmen Square crackdown and the mass starvation of Mao Zedong's regime.

A survey released last week suggested 69% of students opposed the classes.

The climbdown came a day after activists said more than 100,000 protesters had rallied at government headquarters. Police put the turnout at 36,000.

Unlike the rest of China, Hong Kong enjoys a high degree of freedom, including a free press, the right to assemble and transparent, accountable institutions.

Our correspondent says the row is the latest example of the cultural, social and political gap that exists between Hong Kong and its mainland masters.

It also highlights the deep suspicion with which many Hong Kong people continue to regard the Chinese government, she adds.