WASHINGTON — The Supreme Court ruled Thursday that the Trump administration cannot include a question about citizenship on the 2020 census form that goes to every U.S. household, giving a win to mostly Democratic populous states that said the question would discourage legal and illegal immigrants from responding and make the population count less accurate.

The court was deeply fractured on the issue, but on the section that essentially eliminated the citizenship question, the vote was 5-4, with Chief Justice John Roberts joining the four-member liberal wing of the court.

The court's majority said the government has the right to ask a citizenship question, but that it needs to properly justify changing the long-standing practice of the Census Bureau. The Trump administration's justification was "contrived," Roberts wrote, and did not appear to be the genuine reason for the change, possibly implying that the real reason was political.

The decision makes it difficult for the Commerce Department to justify the question and make it part of the census before the forms have to be printed in only a few weeks. But it leaves the door open for the government to try again, and some legal experts believe the government could succeed.

“It’s almost a toss up, but I think in the end the census question probably will make it on. If the Census Bureau simply says it wants the question on to get a complete count, the Supreme Court will say that’s OK in the coming weeks,” said Tom Goldstein, publisher of the SCOTUSblog website and a lawyer who argues frequently before the court.

The ruling was a setback for the Trump administration's tough position on immigration. It was also a surprise, because it appeared in April when the case was argued that the court's five-member conservative majority was prepared to rule that Commerce Secretary Wilbur Ross acted within his authority to add the question.

President Donald Trump tweeted Thursday afternoon that he asked lawyers whether the census can be put on hold.

"Seems totally ridiculous that our government, and indeed Country, cannot ask a basic question of Citizenship in a very expensive, detailed and important Census, in this case for 2020," he tweeted.

.....United States Supreme Court is given additional information from which it can make a final and decisive decision on this very critical matter. Can anyone really believe that as a great Country, we are not able the ask whether or not someone is a Citizen. Only in America! — Donald J. Trump (@realDonaldTrump) June 27, 2019

A census is required every 10 years by the Constitution, and the results determine the size of each state's congressional delegation. The data is also used to calculate a local government's share of funds under many federal programs.

A total of 18 states, several of the nation's largest cities and immigrant rights groups sued to block the question, saying it would make immigrants reluctant to respond to the census mailer. As a result, states with large immigrant communities could lose seats in Congress and suffer cuts in government aid programs, their lawsuit said.

Citizenship questions were asked during every census between 1820 and 1950. But from 1960 on, the government sent households a short form that contained only a few questions and did not inquire about citizenship. Both the Census Bureau and the groups behind the lawsuit agreed that the question will reduce the census response rate, especially in immigrant communities. By one government estimate, as many as 6.5 million people might not be counted.

Ross told Congress that he decided to add the question after receiving a letter from the Justice Department that said the citizenship data was needed to properly enforce federal voting laws. But he later admitted during a trial on the issue that he started thinking about the citizenship issue shortly after taking office and suggested that the Justice Department request it.

Led by New York, the states opposing the question also said Ross' directive sidestepped the Census Bureau's longstanding procedures for testing changes to the questionnaire in order to evaluate whether they would lead to an undercount. Because the citizenship question would depress minority responses, the challengers said, including it on the form would actually produce a less accurate count than leaving it off and using Social Security and IRS data to supplement the information gathered from the census form.

Five weeks after the case was argued in late April, the American Civil Liberties Union informed the court that it found evidence suggesting that the idea of including the question originated with an unpublished policy paper by a longtime adviser to the Republican Party. The government's actual goal, the group said, was to dilute the voting power of minority communities.

But the Justice Department dismissed the claim as unfounded and said none of the officials responsible for adding the question had even heard of the policy document.