The US Supreme Court has blocked the Trump administration from adding a question on citizenship to the 2020 census for the time being.
The White House has argued that the question will bolster protections for minority voters.
But opponents say it could deter immigrant households from taking part because of fears that data could be shared with law enforcement agencies.
President Trump responded by saying he would try to delay the census.
Allow Twitter content?
The justices wrote in a 5-4 ruling that the reason for including the question seemed "contrived".
Chief Justice John Roberts joined the court's liberal justices, saying the administration did not provide adequate justification for the question.
The Census Bureau's own experts say it would lead to a major undercount.
Though the ruling deals a blow to the Trump administration, the complicated decision does not bar the question for either its language or the underlying premise.
Instead, by sending the case back to a lower court, Justice Roberts left open the possibility that the Trump administration could provide the necessary justification to add a question on citizenship to the census.
The battle over the 2020 census has played out across the US.
Civil rights groups have called it an attack on people of colour. Three federal judges have issued rulings to block the question, one calling it a threat "to the very foundation" of US democracy.
And though the Trump administration has maintained the question is necessary for an accurate national headcount, the majority decision pointed to a "disconnect between the decision made and the explanation given".
What is the citizenship question?
"Is this person a citizen of the United States?"
If the Trump administration eventually gets its way, federal law will require this question be asked of every living person in the US as part of the 2020 census.
The citizenship question has not appeared on a US census for all Americans since 1950, though it has been asked to some subsets of the population between 1970 and 2000.
The once-a-decade population count helps the US government draw up districts for state and local elections, and determine how much federal funding each state receives - a matter of hundreds of billions of dollars.
US Commerce Secretary Wilbur Ross - the billionaire financier who oversees the Census Bureau - testified to Congress last year that the request for the citizenship question came from the Department of Justice.
According to Mr Ross, the justice department needs more accurate data to enforce the Voting Rights Act, which protects minority voters.
In a 2018 report, Census Bureau researchers found that the inclusion of a citizenship question will likely suppress response rates in households with immigrants and minority groups, leading to a "lower-quality population count".
But Mr Ross has insisted that detailed citizenship data is of "greater importance than any adverse effect" posed by an undercount.
White House fumbles on citizenship question
When it comes to including a citizenship question to the 2020 census, Donald Trump had the US Constitution on his side - but that wasn't enough.
It's been a common critique of the Trump administration - at least from their supporters - that many of the sweeping conservative changes it has tried to achieve have been undermined by ham-handed implementation. Environmental and workplace deregulation and tougher immigration and border policies have been tied up in the courts because officials in charge were either sloppy or unaware of proper procedures.
Much to the delight of the president's political opponents, the citizenship question can be added to this list.
It is well within the power of a presidential administration to ask about citizenship status, a majority of the justices wrote, but it needs to be clear and up-front about why. The Trump team wasn't.
Now it's back to the drawing board for the White House, with little if any time to find a way forward.
Those on the left feared including citizenship would deprived immigrant communities of needed government resources and stripped them - and the Democrats who largely represent them - of political power.
These fears have been put to rest for now.
What's the controversy?
The battle over the 2020 census hinges on the motives underlying the new question.
The White House maintains the decision was made for practical reasons.
"When you have a census and you're not allowed to talk about whether or not somebody's a citizen or not, that doesn't sound so good to me," Mr Trump said to reporters in June.
But critics claim the question has more insidious origins. Democrats and civil rights groups say the question is politically motivated, meant to suppress responses from particular groups, namely immigrants and racial minorities.
"Is it really about citizenship?" said Michigan Democrat Rashida Tlaib. "No. It's about reducing the number of people of colour being counted in the census. That's exactly what it's about."
This suspicion has been fuelled by reports, released last month, that the question was the brainchild of a top Republican political consultant who argued it would help his party politically.
Redistricting strategist Thomas Hofeller, who died last August, had concluded in a 2015 study that adding the question to the 2020 census would create an electoral advantage for Republicans and "non-Hispanic Whites" by altering voting districts.
And released emails show that Mr Ross lobbied the justice department for a question on citizenship, contradicting his previous claims that the request originated from them.
The Supreme Court's decision appears to confirm Mr Ross's decisive role in pushing the question forward.
"Materials before us indicate that Commerce went to great lengths to elicit the request from DOJ (or any other willing agency", Justice Roberts wrote for the majority.
Congressional Democrats have recently ramped up efforts to access more documents that could shed light on the decision.
Last week, after the White House refused to hand over materials regarding the decision to ask the citizenship question, the House Oversight Committee voted to hold both Mr Ross and US Attorney General William Barr in contempt.
Why does it matter?
The Census Bureau's research indicates the citizenship question will dramatically reduce the number of people willing to participate, particularly among those who fear it could lead to deportation.
Adding the question could mean that up to 4 million people - mostly Latinos and African Americans - go uncounted, according to a study from the Urban Institute, a non-partisan research group based in Washington.
The "last-minute introduction" of a citizenship question has incited "a potential chill" among immigrants groups, the study said. Even in a lower-risk scenario, the 2020 count will be less accurate than previous years.
This will almost certainly favour the Republican party, at the expense of Democrats.
The US census determines the size of each state's congressional delegation, and shapes how congressional and state legislative boundaries are drawn within them. The census also guides how an estimated $880bn (£633bn) in public funding is distributed for schools, roads and other public services.
The states with the highest immigration populations, such as California and New Mexico, are at greatest risk of an undercount. Many of these states tend to vote Democrat.
Depressed response rates in these states will allow for electorate boundaries to be redrawn, pulling political power - and funding - away from Democratic-leaning, minority households.
The Supreme Court is expected to rule on the question this month, just in time for the Census Bureau to print out the 1.5bn questionnaires needed to begin the national headcount this summer.