The government may not strip someone’s citizenship for lying during the naturalization process without proving the falsehood is relevant, the Supreme Court ruled Thursday.

The court unanimously rejected the government’s view that simply proving that someone lied during the process was enough. Justice Elena Kagan said that would give the government too much power.

“The government opens the door to a world of disquieting consequences,” Kagan wrote, adding that it would “give prosecutors nearly limitless leverage — and afford newly naturalized Americans precious little security.”

The government’s view that any lie is enough is a long-held one, but it has taken on new importance with the Trump administration’s focus on deportation.

Kagan wrote that the government must show that an illegal act by the defendant “played some role in her acquisition of citizenship.”

When the illegal act is making a false statement, she said, prosecutors must show the lie was about facts that might have mattered to an immigration official, either because it would have justified denying naturalization or led to other facts that would have warranted that result.

The case at the court involved a Bosnian native, Divna Maslenjak, who was criminally prosecuted for lying on her application about her husband’s military service. She was deported by the Obama administration, which held the broad view that any misrepresentation — whether relevant or not — was enough to give the government the right to consider revocation.

Maslenjak was granted refu­gee status in 1999 along with her family. She is an ethnic Serb and said she and her family faced persecution. She became a U.S. citizen in 2007. During her immigration hearing, she said her husband evaded conscription into the army. In fact, he had served in a Bosnian unit implicated in war crimes.

Divna Maslenjak was convicted, and she and her husband were deported to Serbia, while their children were allowed to remain in Ohio.

The court’s decision should mean she gets a new trial, at which the government would have to prove Maslenjak’s falsehoods were material to the granting of naturalization.

Although the court’s ruling did not venture an opinion, justices said at oral argument that the government might well prove Maslenjak’s lies were material.

The court was analyzing a law that makes it a crime to “knowingly procure, contrary to law, the naturalization of any person.” The most natural understanding of that, Kagan said, is that the illegal act must have somehow contributed to the obtaining of citizenship.

She proposed consideration of this sentence: “John obtained the painting illegally.” One would think he stole it, or wrote a bad check, she wrote. But if you said he obtained it illegally but his unlawful act played no role in obtaining, she added, “you would think it nonsense — or perhaps the opening of a riddle.”

Kagan’s test for when a falsehood is material went too far for some members of the court. Justice Neil M. Gorsuch, joined by Justice Clarence Thomas, said the court did not need to decide more than the falsehood had to be material.

“For my part, I believe it is work enough for the day to recognize that the statute requires some proof of causation, that the jury instructions here did not, and to allow the parties and courts of appeals to take it from there as they usually do,” Gorsuch wrote. “This court often speaks most wisely when it speaks last.”

Kagan responded that such a “halfway-decision” would be of little help. “The government needs to know what prosecutions to bring; defendants need to know what defenses to offer; and district courts need to know how to instruct juries.”

Justice Samuel A. Alito Jr. also differed slightly from Kagan’s reasoning, but he agreed with the outcome of Maslenjak v. United States.

The court also ruled Thursday that a teenage murder defendant in Massachusetts does not get a new trial because his lawyer did not object when a judge closed the courtroom to the public during jury selection.

Kentel Myrone Weaver was claiming ineffectiveness of counsel. His lawyer acknowledged that he thought the judge was allowed to close the court because of overcrowding. The Supreme Court has said it is a constitutional violation.

But Justice Anthony M. Kennedy wrote for six other members of the court that Weaver had not shown that “counsel’s shortcomings led to a fundamentally unfair trial.”

Justices Stephen G. Breyer and Kagan dissented.

That case is Weaver v. Massachusetts.