BEIJING—China adopted a sweeping national-security law that the government says is needed to counter emerging threats but that critics say may be used to quash dissent and exclude foreign investment.

Approved by the legislature’s standing committee Wednesday, the law sets an expansive definition of national security that outlaws threats to China’s government, sovereignty and national unity as well as its economy, society, and cyber and space interests.