TOKYO — In an unusual late-night session with protesters chanting outside, Parliament passed a secrecy law on Friday that the prime minister said would strengthen national security but opponents warned would stifle democracy.

Prime Minister Shinzo Abe used his governing coalition’s majority to get the bill approved by Parliament in about four weeks, a blistering speed by the standards of Japan’s consensus-driven political world. This brought howls of protest from opposition parties that Mr. Abe and his Liberal Democratic Party were ramming through a potentially dangerous new law without giving them, or the public, a chance to understand it first.

Mr. Abe says the new law will improve Japan’s ability to manage delicate diplomatic, defense and counterterrorism-related information, making it easier to share classified intelligence with allies like the United States. The move is part of his broader strategy for strengthening Japan’s defense posture that also includes a new American-style national security council, which held its first meeting on Wednesday.

However, the secrecy law has drawn intense criticism from news media, law and civil rights groups, who say its broad and vague definition of what constitutes a secret will only further strengthen Japan’s already-secretive central bureaucrats. They also warn that the law’s stiff penalty of up to 10 years in prison could be used to scare would-be whistle-blowers into silence, or even harass journalists, harming the public’s right to know.