BEIJING—Chinese legislators passed a law on Thursday granting police broad authority to supervise foreign nonprofit groups, reinforcing President Xi Jinping’s drive to consolidate government control over China’s society, culture and economy. The law says any activities of foreign nonprofits that threaten national security or ethnic harmony will be punished. A draft of the law released last year drew an outpouring of opposition from foreign governments, rights groups, business associations and academics for being overly broad…