Critics said the move goes against the "one country, two systems" framework in which Beijing promised the city freedoms not found on the mainland.
The bill, one of the most controversial items on the agenda of the National People's Congress in years, drew strong rebukes from the US government and rights groups.
Beijing appears to have lost patience, however, and is determined to assert greater control in Hong Kong and limit opposition activity.
"Xi Jinping has torn away the whole pretence of 'one country, two systems'," former pro-democracy legislator Lee Cheuk-yan said of China’s leader.
Speaking at a news briefing by opposition parties and activists, he said that the move shows Beijing is "directly taking control".
"They're trying to ban every organisation in Hong Kong who dares to speak out against the Communist Party," he said, describing it as a challenge to global values such as freedom and liberty.
Wang Chen, vice chairman of the National People’s Congress, said the protests and violence in Hong Kong had challenged the "one country, two systems" principle and the aim of the legislation was to stop any behaviour that posed potential security threats.
He said Hong Kong's legal system and enforcement must be established and improved "at the state level" to "change the long-lasting situation of defencelessness in the national security affairs in Hong Kong".
China's foreign ministry said Hong Kong is China's internal affair and "no foreign country has the right to intervene".
"The Chinese government is determined in safeguarding national sovereignty, security and development interests, following through the policy of ‘one country, two systems’, and opposing any external interference in Hong Kong affairs," ministry spokesperson Zhao Lijian said.
A previous effort to pass such legislation in Hong Kong's legislature was abandoned after massive street protests in 2003.
This time, Beijing has decided to circumvent the territory's legislature using what critics say are dubious legal grounds under the Basic Law - which has served as a sort of constitution for Hong Kong since its return to China from British colonial rule in 1997.
Hong Kong said in a statement that the national security law "will not affect the legitimate rights and freedoms enjoyed by Hong Kong residents under the law, or the independent judicial power, including that of final adjudication, exercised by the judiciary in Hong Kong".
She added: "I deeply believe that the national law to be enacted by the Standing Committee of the NPC will seek to practically and effectively prevent and curb acts and activities that seriously undermine national security, as well as sanction those who undermine national security by advocating 'Hong Kong independence' and resorting to violence."