WASHINGTON — The Trump administration cannot add a citizenship question to the 2020 census, at least for now, the US Supreme Court ruled Thursday.

In a complicated decision, in which both the court’s liberal and conservative wings joined in part and dissented in part, the Supreme Court sent the case back to the Commerce Department, asking for a better explanation of why the Trump administration tried to add a citizenship question in the first place.

Chief Justice John Roberts, joined by the court’s liberal wing, found that the reason the administration gave for adding the question — enforcing voting rights — was “contrived” and didn’t line up with the evidence. But Roberts also wrote that the question itself wasn’t unconstitutional, a finding the court’s conservatives agreed with, and left open the possibility for it to be added in the future under different circumstances.

Unlike in the court’s other blockbuster decision Thursday on partisan gerrymandering, a majority of the justices also found that courts could be involved in reviewing decisions by federal officials when it came to managing the decennial census.

In his opinion, Roberts wrote that Commerce Secretary Wilbur Ross’s “decision was reasonable and reasonably explained, particularly in light of the long history of the citizenship question on the census.” (The census included a citizenship question until 1950.)

But the problem was that “the evidence tells a story that does not match the explanation [Ross] gave for his decision,” Roberts wrote.

Ross had said that he decided to add a citizenship question to the 2020 census because the Justice Department needed that data to help with voting rights enforcement. But, Roberts wrote, the court was presented with evidence that that wasn’t actually what motivated the question; Ross had decided to add the question long before he came up with that justification, Roberts wrote.

“In the Secretary’s telling, Commerce was simply acting on a routine data request from another agency. Yet the materials before us indicate that Commerce went to great lengths to elicit the request from DOJ (or any other willing agency),” Roberts wrote.

Roberts concluded that “[r]easoned decisionmaking under the Administrative Procedure Act calls for an explanation for agency action. What was provided here was more of a distraction.”

Kelly Laco, a Justice Department spokesperson, said that the administration will continue fighting. “We are disappointed by the Supreme Court’s decision today. The Department of Justice will continue to defend this Administration’s lawful exercises of executive power,” Laco said in a statement.

The Census Bureau is set to begin sending out questionnaires early next year. The US Constitution requires the federal government to do a count every 10 years, and the data is used to decide how billions of dollars in federal funds are spent, how many representatives in Congress each state gets, and the size and shape of congressional districts.

The Constitution doesn’t specify that only citizens should be counted and, as Justice Sonia Sotomayor noted during arguments, the main census survey hasn’t asked about citizenship in decades.

In a series of tweets Thursday, President Donald Trump said it was "ridiculous" that his administration "cannot ask a basic question of Citizenship" in the census survey and that he has asked "the lawyers" to "delay" on the 2020 census until the issue is resolved. Under federal law, the census must be taken by April 1, 2020.

Ross announced in March 2018 that he would add a citizenship question to the 2020 census. Lawsuits challenging the decision were filed in courts across the country, and the Trump administration largely lost at every stage. Although by law the Census Bureau can’t share data with law enforcement agencies, the challengers argued that wouldn’t ease the fears that noncitizens, and immigrant communities more generally, have about sharing their immigration status with the government, and that those households would either provide false information or not return their surveys at all.

Lower court judges repeatedly blocked the administration from adding the question, finding that Ross ignored a wealth of information showing it would hurt the accuracy of the census, and that Ross’s stated reason for including the question — that the Justice Department needed it to help with voting rights enforcement — was a pretext.

But while Roberts agreed Thursday that the reasoning was pretextual, he wrote that Ross “justifiably” rejected arguments that adding the question could hurt the census’ accuracy because he found the evidence “inconclusive” and decided that having “more complete and accurate citizenship data ... was worth the risk of a potentially lower response rate.”

The court did not address, however, what the challengers argued was bombshell new evidence revealed last month: documents found on the hard drive of a dead Republican strategist that appeared to offer new insight into the origins of the administration’s plan to add the citizenship question. The strategist, Thomas Hofeller, had done a study in 2015 about using citizen population data to draw electoral districts, and concluded that it would “be advantageous to Republicans and Non-Hispanic Whites.”

The files also appeared to indicate that Hofeller had written a draft letter to the Department of Commerce asking for a citizenship question, and that letter had made its way to John Gore, the senior Justice Department official who ultimately asked Commerce to add the question. The challengers argued that DOJ’s letter “bears striking similarities” to Hofeller’s study.

The Justice Department countered that the revelation of the Hofeller files wasn’t significant or relevant to the litigation, saying that his 2015 study “played no role” in the decision to request the citizenship question. The Justice Department argued that adding the question would help enforce voting rights laws.

“These eleventh-hour allegations by the plaintiffs, including an accusation of dishonesty against a senior Department of Justice official, are false,” a Justice Department spokesperson said in a statement at the time. “These unfounded allegations are an unfortunate last-ditch effort to derail the Supreme Court’s consideration of this case.”

Groups challenging the citizenship question notified the Supreme Court about the Hofeller materials, but the court did not take any action before issuing its decision.

The challengers, meanwhile, also asked lower court judges in New York and Maryland to consider the new Hofeller evidence. If those judges ultimately issue new rulings that offer different analysis of the citizenship question based on those materials, it’s possible the issue could again work its way back up to the Supreme Court.

In Maryland, for instance, the judge agreed with the challengers that the administration violated administrative law, but concluded there wasn’t enough evidence that the question was motivated by the administration’s alleged desire to discriminate against immigrants and minorities. The challengers have asked him to reconsider that in light of the Hofeller files.